question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-unused-vars should report all unused function parameters that match the configured setting

See original GitHub issue

I’m creating this as an attempt to refocus the discussion in #9750 into a specific proposal I have (although I think @g-plane would agree with me as well).

What rule do you want to change?

no-unused-vars

Does this change cause the rule to produce more or fewer warnings?

More

How will the change be implemented? (New option, new default behavior, etc.)?

New default behavior for args: "after-used" option: Report all unused parameters which occur after the last used parameter. This would be done as 1 lint message per unused parameter.

Note that this is not really a breaking change:

  • When the user has no unused parameters after the last used parameter, the rule will continue not to report any violations.
  • When the user has at least one unused parameter after this last used parameter, we currently report 1 parameter at a time.
    • When the user removes the unused parameter, we report the next unused parameter. Net effect for the user is to (eventually) see lint messages for all unused parameters after the last used parameter.
    • This proposal is just to report them all at once.

Please provide some example code that this change will affect:

/* eslint no-unused-vars: ["error", { "args": "after-used" }] */
function (a, b, c, d, e) {
    c();
}

For more examples, see demo.

What does the rule currently do for this code?

For code block above: Reports that e is unused.

For demo: See lint results.

What will the rule do after it’s changed?

For code block above: Reports that d, and e are all unused.

  • a, b, d, and e are unused.
  • But d and e are after the last used parameter (c).
  • So report both d and e.

For demo: See comments in code.

Note: args: "all" works correctly and needs no changes.


I’ll champion.

If there’s a strong reason for reporting only one of the unused arguments (and no, “the docs say so” doesn’t count, that’s circular reasoning), that can be expressed here as part of a 👎 to this proposal.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

3reactions
not-an-aardvarkcommented, Jan 31, 2018

@not-an-aardvark Are you saying that previously, the “after-used” option worked the way that @platinumazure is now proposing?

Yes, I think that’s correct based on looking at the old versions of the code.

In any case, the proposal says this change introduces more warnings and is an enhancement, so it must be a breaking change by our definition.

I think this might be coming from an ambiguity in our definition. To be clear, this increases the number of warnings on some lint runs, but it only does this in cases where at least one warning would have been reported anyway. In other words, there are no cases in which a warning would start to be reported where no warnings were reported before.

There was a similar case in https://github.com/eslint/eslint/pull/7095#issuecomment-246195723 when we updated quote-props to report individual errors for each property, rather than reporting the object as a whole. We ended up calling that a semver-minor change.

3reactions
platinumazurecommented, Jan 30, 2018

@nzakas I’ve added “breaking” label for now, but I disagree that this is a breaking change. I’ve explained why in the initial post, but here it is again for convenience:

Note that this is not really a breaking change:

  • When the user has no unused parameters after the last used parameter, the rule will continue not to report any violations.
  • When the user has at least one unused parameter after this last used parameter, we currently report 1 parameter at a time.
    • When the user removes the unused parameter, we report the next unused parameter. Net effect for the user is to (eventually) see lint messages for all unused parameters after the last used parameter.
    • This proposal is just to report them all at once.

The overall number of errors is actually unchanged; it’s just reported over one linting runs. And-- this is the important part-- there is no situation where 0 issues are currently reported, and >0 issues are reported under this proposal.

Using this example as a reference:

/* eslint no-unused-vars: ["error", { "args": "after-used" }] */
function (a, b, c, d, e) {
    c();
}

In my example, we instead go from 1 issue reported in 2 lint runs (e reported, then d when e is removed), to 2 issues reported (d and e in the same run).

In this example:

/* eslint no-unused-vars: ["error", { "args": "after-used" }] */
function (a, b, c) {
    c();
}

No report is generated right now, and no report will be generated with this proposal.

So since there are no new linting errors introduced where previously there were no linting errors, I don’t think this is a breaking change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-unused-vars - ESLint - Pluggable JavaScript Linter
This rule is aimed at eliminating unused variables, functions, and function parameters. A variable foo is considered to be used if any of...
Read more >
"no-unused-vars" on function parameters within TypeScript ...
'param' is defined but never used. Allowed unused args must match /^_/u. Here's what my .eslintrc.json looks like: { ...
Read more >
no-unused-vars - TypeScript ESLint
no-unused-vars. Disallow unused variables. ✓. Extending "plugin:@typescript-eslint/recommended" in an ESLint configuration enables this rule.
Read more >
Disallow unused variables and arguments ( no-unused-vars ...
This rule leverages the TypeScript compiler's unused variable checks to report. This means that with all rule options set to false , it...
Read more >
The 3 Best ESLint No-Unused-Vars Option Settings (Make it ...
The no-unused-vars rule is one of the most important ESLint rules for keeping code ... Here's the code from my .eslintrc.json configuration:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found