JSHint silence when

Consider the following standard Express function:

if (app.get('env') === 'development') { app.use(function (err, req, res, next) { res.status(err.status || 500); res.render('error', { message: err.message, error: err }); }); } 

The following warning is displayed:

'next' is defined but never used. - W098

I know that I can turn off all warnings, but that’s not what I want. I need to disable JSHint only for a specific parameter ("next" in the snippet above.)

I did not see clear answers to this seemingly common problem. Any ideas?

Thanks!

+6
source share
2 answers

In this case, you can do something like below

 if (app.get('env') === 'development') { app.use(function (err, req, res, next) { /*jshint unused: vars*/ var foo; res.status(err.status || 500); res.render('error', { message: err.message, error: err }); }); } 

Now jshint will not cry about next , although it will still warn about foo , which will be determined, but will not be used.

It is important that this suppression will be related to the scope of the function.

+3
source

Yes it is possible!

If you use the standard JSHint setting, the accepted answer to this thread is also your answer: Is there a way to suppress the JSHint warning for one given string? It shows how to use comments to conditionally ignore certain errors / warnings due to the fact that they were thrown into JSHint.

If you use a build tool such as Gulp or Grunt, you can add this to your parameters in your plugin task configuration. For example, with Grunt: See the “Ignoring Certain Warnings” section at https://github.com/gruntjs/grunt-contrib-jshint/blob/master/README.md .

Hope this helps!

+1
source

Source: https://habr.com/ru/post/974621/


All Articles