noUnusedFunctionParameters
¥Summary
-
规则生效日期:
v1.8.0¥Rule available since:
v1.8.0 -
诊断类别:
lint/correctness/noUnusedFunctionParameters¥Diagnostic Category:
lint/correctness/noUnusedFunctionParameters -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
¥How to configure
{ "linter": { "rules": { "correctness": { "noUnusedFunctionParameters": "error" } } }}¥Description
禁止未使用的函数参数。
¥Disallow unused function parameters.
此规则有一个例外:以下划线开头的参数,例如 function foo(_a, _b) {}。
¥There is an exception to this rule:
parameters that starts with underscore, e.g. function foo(_a, _b) {}.
¥Examples
¥Invalid
function foo(myVar) { console.log('foo');}code-block.js:1:14 lint/correctness/noUnusedFunctionParameters FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This parameter 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 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 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 │
¥Valid
function foo(myVar) { console.log(myVar);}function withObjectSpread({ a, ...rest }) { return rest;}¥Options
该规则具有以下选项
¥The rule has the following options
ignoreRestSiblings
Section titled “ignoreRestSiblings”自 v2.1.0 版本起:
¥Since v2.1.0
是否忽略使用扩展符解构对象的未使用变量。示例:当 function({ a, b, ...rest }) { return rest;} 中的 a 和 b 设置为 false 时,此规则应忽略它们。
¥Whether to ignore unused variables from an object destructuring with a spread.
Example: a and b in function({ a, b, ...rest }) { return rest;} should be ignored by this rule when set to false.
默认为 true。
¥Defaults to true.
{ "linter": { "rules": { "correctness": { "noUnusedFunctionParameters": { "options": { "ignoreRestSiblings": false } } } } }}function withObjectSpread({ b, ...rest }) { return rest;}code-block.js:1:29 lint/correctness/noUnusedFunctionParameters ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This parameter is unused.
> 1 │ function withObjectSpread({ b, …rest }) {
│ ^
2 │ return rest;
3 │ }
ℹ Unused parameters might be the result of an incomplete refactoring.
¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号