noUselessUndefined
¥Summary
-
规则生效日期:
v2.0.0¥Rule available since:
v2.0.0 -
诊断类别:
lint/nursery/noUselessUndefined¥Diagnostic Category:
lint/nursery/noUselessUndefined -
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
与
unicorn/no-useless-undefined相同¥Same as
unicorn/no-useless-undefined
-
¥How to configure
{ "linter": { "rules": { "nursery": { "noUselessUndefined": "error" } } }}¥Description
禁止使用无用的 undefined 指令。
¥Disallow the use of useless undefined.
undefined 是新变量、参数、返回语句等的默认值,因此指定它不会有任何区别。
¥undefined is the default value for new variables, parameters, return statements, etc., so specifying it doesn’t make any difference.
¥Examples
¥Invalid
let foo = undefined;code-block.js:1:11 lint/nursery/noUselessUndefined FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Don’t use unnecessary undefined.
> 1 │ let foo = undefined;
│ ^^^^^^^^^
2 │
ℹ undefined is the default value for new variables, parameters, return statements, etc… so specifying it doesn’t make any difference.
ℹ Safe fix: Remove the undefined.
1 │ let·foo·=·undefined;
│ -----------
const {foo = undefined} = bar;code-block.js:1:14 lint/nursery/noUselessUndefined FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Don’t use unnecessary undefined.
> 1 │ const {foo = undefined} = bar;
│ ^^^^^^^^^
2 │
ℹ undefined is the default value for new variables, parameters, return statements, etc… so specifying it doesn’t make any difference.
ℹ Safe fix: Remove the undefined.
1 │ const·{foo·=·undefined}·=·bar;
│ -----------
function foo() { return undefined;}code-block.js:2:11 lint/nursery/noUselessUndefined FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Don’t use unnecessary undefined.
1 │ function foo() {
> 2 │ return undefined;
│ ^^^^^^^^^
3 │ }
4 │
ℹ undefined is the default value for new variables, parameters, return statements, etc… so specifying it doesn’t make any difference.
ℹ Safe fix: Remove the undefined.
2 │ ···return·undefined;
│ ---------
function* foo() { yield undefined;}code-block.js:2:9 lint/nursery/noUselessUndefined FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Don’t use unnecessary undefined.
1 │ function* foo() {
> 2 │ yield undefined;
│ ^^^^^^^^^
3 │ }
4 │
ℹ undefined is the default value for new variables, parameters, return statements, etc… so specifying it doesn’t make any difference.
ℹ Safe fix: Remove the undefined.
2 │ ··yield·undefined;
│ ---------
function foo(bar = undefined) {}code-block.js:1:20 lint/nursery/noUselessUndefined FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Don’t use unnecessary undefined.
> 1 │ function foo(bar = undefined) {}
│ ^^^^^^^^^
2 │
ℹ undefined is the default value for new variables, parameters, return statements, etc… so specifying it doesn’t make any difference.
ℹ Safe fix: Remove the undefined.
1 │ function·foo(bar·=·undefined)·{}
│ -----------
function foo({bar = undefined}) {}code-block.js:1:21 lint/nursery/noUselessUndefined FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Don’t use unnecessary undefined.
> 1 │ function foo({bar = undefined}) {}
│ ^^^^^^^^^
2 │
ℹ undefined is the default value for new variables, parameters, return statements, etc… so specifying it doesn’t make any difference.
ℹ Safe fix: Remove the undefined.
1 │ function·foo({bar·=·undefined})·{}
│ -----------
¥Valid
let foo;const {foo} = bar;function foo() { return;}function* foo() { yield;}function foo(bar) {}function foo({bar}) {}foo();¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号