noUselessUndefined
Summary
Section titled “Summary”- Rule available since:
v2.0.0 - Diagnostic Category:
lint/complexity/noUselessUndefined - This rule isn’t recommended, so you need to enable it.
- This rule has a safe fix.
- The default severity of this rule is information.
- Sources:
- Same as
unicorn/no-useless-undefined
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "complexity": { "noUselessUndefined": "error" } } }}Description
Section titled “Description”Disallow the use of useless undefined.
undefined is the default value for new variables, parameters, return statements, etc., so specifying it doesn’t make any difference.
return undefined is allowed when the enclosing function has a return type annotation other than undefined or void.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”let foo = undefined;code-block.js:1:11 lint/complexity/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/complexity/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/complexity/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/complexity/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/complexity/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/complexity/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})·{}
│ -----------
let foo;const {foo} = bar;function foo() { return;}function* foo() { yield;}function foo(bar) {}function foo({bar}) {}foo();function foo(): string | undefined { return undefined;}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.