noUselessDefaultAssignment (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.9 - Diagnostic Category:
lint/nursery/noUselessDefaultAssignment - This rule has an unsafe fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
- Inspired from
@typescript-eslint/no-useless-default-assignment
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noUselessDefaultAssignment": "error" } } }}Description
Section titled “Description”Disallow default values that can never be used.
A default value only applies when the value it replaces is undefined.
If the type says the value can’t be undefined, the default is dead code.
This rule checks destructured object properties, destructured tuple elements, and parameters of callbacks passed directly to a call.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”function greet({ name = "friend" }: { name: string }) { return `Hello, ${name}`;}/invalid-parameter-property.ts:1:25 lint/nursery/noUselessDefaultAssignment FIXABLE ━━━━━━━━━━━━━━
ℹ This default value is never used.
> 1 │ function greet({ name = "friend" }: { name: string }) {
│ ^^^^^^^^
2 │ return `Hello, ${name}`;
3 │ }
ℹ A default value only applies when the value is undefined, but the type of this property doesn't include undefined.
ℹ Remove the default value, or add undefined to the type if the value can be missing.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Remove the default value.
1 │ function·greet({·name·=·"friend"·}:·{·name:·string·})·{
│ -----------
const { name = "friend" } = { name: "Ada" };/invalid-variable-property.ts:1:16 lint/nursery/noUselessDefaultAssignment FIXABLE ━━━━━━━━━━━━━━━
ℹ This default value is never used.
> 1 │ const { name = "friend" } = { name: "Ada" };
│ ^^^^^^^^
2 │
ℹ A default value only applies when the value is undefined, but the type of this property doesn't include undefined.
ℹ Remove the default value, or add undefined to the type if the value can be missing.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Remove the default value.
1 │ const·{·name·=·"friend"·}·=·{·name:·"Ada"·};
│ -----------
declare const pair: [string, number];const [label = "none", count] = pair;/invalid-tuple-element.ts:2:16 lint/nursery/noUselessDefaultAssignment FIXABLE ━━━━━━━━━━━━━━━━━━━
ℹ This default value is never used.
1 │ declare const pair: [string, number];
> 2 │ const [label = "none", count] = pair;
│ ^^^^^^
3 │
ℹ A default value only applies when the value is undefined, but the type of this array element doesn't include undefined.
ℹ Remove the default value, or add undefined to the type if the value can be missing.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Remove the default value.
2 │ const·[label·=·"none",·count]·=·pair;
│ ---------
declare function onMessage(listener: (message: string) => void): void;onMessage((message = "") => console.log(message));/invalid-callback-parameter.ts:2:22 lint/nursery/noUselessDefaultAssignment FIXABLE ━━━━━━━━━━━━━━
ℹ This default value is never used.
1 │ declare function onMessage(listener: (message: string) => void): void;
> 2 │ onMessage((message = "") => console.log(message));
│ ^^
3 │
ℹ A default value only applies when the value is undefined, but the type of this parameter doesn't include undefined.
ℹ Remove the default value, or add undefined to the type if the value can be missing.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Remove the default value.
2 │ onMessage((message·=·"")·=>·console.log(message));
│ -----
function greet({ name = "friend" }: { name?: string }) { return `Hello, ${name}`;}
const { label = "none" } = { label: undefined };
declare const names: string[];const [first = "nobody"] = names;
declare function onMessage(listener: (message?: string) => void): void;onMessage((message = "") => console.log(message));See Also
Section titled “See Also”- If you want to remove default values that are
undefined, seenoUselessUndefined.
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.