rondevera/jslintmate

Unused variables in callbacks

Opened this issue · 4 comments

The previous version reported unused variables only when they were declared with var (and not used). The latest version now reports them when they are defined in function (...).

Would it be possible to differentiate between those two? I find it useful to keep this detection on in order to remove some vars I set up (sometimes at a cost) without using them, but when using callbacks I often like to list all the data I'm expecting to get (especially if I have a lot of similar callbacks in a row). Ideally I could get warnings for the former but not for the latter.

Thanks!

Thanks for reporting this, Robin. Are you having this issue with JSLint or JSHint?

With JSHint. Thanks for looking into this.

This new behavior is happening because of a recent change in JSHint itself. Each new release of JSLintMate just contains the latest version of JSLint and JSHint, which is why it's appearing now.

It looks like this has been addressed in a recently JSHint nightly build: jshint/jshint#639

Other related discussions:

If you'd like to use a version of JSHint other than JSLintMate's packaged version (e.g., if you want to use a JSHint nightly build), you can configure JSLintMate to use a custom linter. Here's how: https://github.com/rondevera/jslintmate#custom-jslintjshint-builds

I'm kinda plagued by this one too. My programmer OCD kicks in if I leave out variables as in other languages it changes the signature of the function.

My solution is to comment out the arguments that I don't need. That way they are still documented in code that they are an option, but don't throw linter errors. I've been seeing this practice crop up for more and more boilerplate javascript code I've used.

function temp (arg1 /* arg2, arg3, ...*/) { // Doesn't throw errors and is completely valid 
    return arg1;
}