`no-unused-vars` should not include function parameters
See original GitHub issueDescription
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:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Is
no-unused-vars: ["error", { "args": "none" }]
what you are looking for?That is great @ilyavolodin, I’ll try it out. Feel free to close this issue whenever you want.