noUnusedFunctionParameters (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v1.8.0 - Diagnostic Category:
lint/correctness/noUnusedFunctionParameters - This rule is recommended, meaning it is enabled by default.
- This rule has an unsafe fix.
- The default severity of this rule is warning.
How to configure
Section titled “How to configure”{ "linter": { "rules": { "correctness": { "noUnusedFunctionParameters": "error" } } }}Description
Section titled “Description”Disallow unused function parameters.
Parameters whose names start with an underscore are ignored. The underscore communicates
that the parameter is intentionally unused, for example function foo(_a, _b) {}.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”function foo(myVar) { console.log('foo');}code-block.js:1:14 lint/correctness/noUnusedFunctionParameters FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This parameter myVar is unused.
> 1 │ function foo(myVar) {
│ ^^^^^
2 │ console.log('foo');
3 │ }
ℹ Unused parameters might be the result of an incomplete refactoring.
ℹ Unsafe fix: If this is intentional, prepend myVar with an underscore.
1 │ - function·foo(myVar)·{
1 │ + function·foo(_myVar)·{
2 2 │ console.log('foo');
3 3 │ }
new Promise((accept, reject) => { window.setTimeout(accept, 1000);});code-block.js:1:22 lint/correctness/noUnusedFunctionParameters FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This parameter reject is unused.
> 1 │ new Promise((accept, reject) => {
│ ^^^^^^
2 │ window.setTimeout(accept, 1000);
3 │ });
ℹ Unused parameters might be the result of an incomplete refactoring.
ℹ Unsafe fix: If this is intentional, prepend reject with an underscore.
1 │ - new·Promise((accept,·reject)·=>·{
1 │ + new·Promise((accept,·_reject)·=>·{
2 2 │ window.setTimeout(accept, 1000);
3 3 │ });
const squares = [[1, 1], [2, 4], [3, 9], [4, 16]];squares.filter(([k, v]) => v > 5);code-block.js:2:18 lint/correctness/noUnusedFunctionParameters FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This parameter k is unused.
1 │ const squares = [[1, 1], [2, 4], [3, 9], [4, 16]];
> 2 │ squares.filter(([k, v]) => v > 5);
│ ^
3 │
ℹ Unused parameters might be the result of an incomplete refactoring.
ℹ Unsafe fix: If this is intentional, prepend k with an underscore.
1 1 │ const squares = [[1, 1], [2, 4], [3, 9], [4, 16]];
2 │ - squares.filter(([k,·v])·=>·v·>·5);
2 │ + squares.filter(([_k,·v])·=>·v·>·5);
3 3 │
function foo(myVar) { console.log(myVar);}function foo(_myVar) {}function withObjectSpread({ a, ...rest }) { return rest;}Options
Section titled “Options”The rule has the following option.
ignoreRestSiblings
Section titled “ignoreRestSiblings”Since v2.1.0
Ignores unused names taken from an object parameter when the same parameter also collects
the remaining properties, as in function({ a, ...rest }) { return rest; }.
Defaults to true.
Set this option to false to report those unused properties.
{ "linter": { "rules": { "correctness": { "noUnusedFunctionParameters": { "level": "on", "options": { "ignoreRestSiblings": false } } } } }}function withObjectSpread({ b, ...rest }) { return rest;}code-block.js:1:29 lint/correctness/noUnusedFunctionParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This parameter b is unused.
> 1 │ function withObjectSpread({ b, ...rest }) {
│ ^
2 │ return rest;
3 │ }
ℹ Unused parameters might be the result of an incomplete refactoring.
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.