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 not include function parameters

See original GitHub issue

Description

While function parameters are seen as variables to use inside the function itself, they can also alter external behaviour depending on the number of parameters. Two notable examples:

// With mocha we make the function async if we include an extra parameter
it('is sync', () => {});
it('is async', (done) => {});  // done is never used :(


// With express we make a function an error handler with an extra param:
// Normal function:
app.use((req, res, next) => {});

// Error handler:
app.use((err, req, res, next) => {});

This is used all around Node.js environment, including the core (see crypt functions). My problem is with the latter express example; I’m extending express’ behaviour but I do not allow for error handlers when modernizing an old middleware. So I have this test:

it('cannot handle error middleware', async () => {
  await throws(() => modern((err, req, res, next) => {}));
});

And eslint is complaining as the parameters are not used, but they are needed since modern() will only throw an error with 4+ parameters.

So I am reporting this as an eslint bug since here it is assumed that function parameters can only be used inside a function, while they can actually modify the behaviour outside of the function and thus be required.

Tell us about your environment

  • ESLint Version: v3.19.0
  • Node Version: v7.7.4
  • npm Version: 4.1.2

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

{
  "parserOptions": {
    "ecmaVersion": 8
  },
  "plugins": ["jasmine"],
  "env": {
    "browser": true,
    "commonjs": true,
    "es6": true,
    "jasmine": true,
    "node": true
  },
  "extends": "eslint:recommended",
  "rules": {
    "indent": ["error",2],
    "linebreak-style": ["error", "unix"],
    "quotes": ["error", "single"],
    "semi": ["error", "always"],
    "no-console": "off"
  }
}

What did you expect to happen?

What actually happened? Please include the actual, raw output from ESLint.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ilyavolodincommented, May 28, 2017

Is no-unused-vars: ["error", { "args": "none" }] what you are looking for?

0reactions
franciscopcommented, May 29, 2017

That is great @ilyavolodin, I’ll try it out. Feel free to close this issue whenever you want.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"no-unused-vars" on function parameters within TypeScript ...
Specially, with VSCode, I have seen stale errors until I restart the IDE. It may not help, but may worth a try after...
Read more >
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 >
Disallow unused variables and arguments ( no- ...
When true, this option will ignore unused function arguments if the arguments proceeding arguments are used. Examples of invalid code with { ...
Read more >
Rule no-unused-vars
This rule is aimed at eliminating unused variables, functions and variables in parameters of functions, as such, warns when one is found. A...
Read more >
no-unused-vars - TypeScript ESLint
How to Use​ ·.exports = { · "rules": { · // Note: you must disable the base rule as it can report incorrect...
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