biome complexity/noUselessUndefinedInitialization
labelled safe
Analysis Nemotron 3 Super
Flags initializations where a variable is explicitly set to `undefined`, since uninitialized variables already have that value.
Fix: Removes the `= undefined` initializer from the variable declaration, leaving only the declaration (and any other declarators in the same statement), preserving leading/trailing whitespace but moving any inline comments attached to the initializer or declarator to the end of the full declaration statement.
10 hazards
- In a `for` loop initializer like `for (let i = 0, j = undefined; i < n; i++)`, removing `j = undefined` changes the loop step syntax if `j` is the last declarator, potentially creating invalid syntax.
- If the variable is declared in a comma expression such as `(x = 1, y = undefined)`, removing `= undefined` alters the expression’s value and side-effect timing.
- In destructuring patterns like `[a = undefined] = []`, removing the default value changes matching behavior when the source array has fewer elements.
- When the initializer is part of a larger expression like `if ((let x = undefined) === null)`, the removal breaks grammar because `let` cannot appear in that position without an initializer in older syntax interpretations.
- If the variable name is `undefined` itself (e.g., `let undefined = 42;` in non-strict mode), the fix would leave `let undefined;` which is a syntax error in strict mode and changes meaning in sloppy mode.
- In conditional declarations like `if (true) let x = undefined;`, the autofix produces `if (true) let x;` which is invalid syntax because `let` declarations in statement position require a block.
- When the declaration includes a trailing comma like `let a = undefined,`, removing the initializer leaves `let a,` which is a syntax error due to the dangling comma.
- If the variable is declared in a `with` object property initializer like `with ({ get x() { return undefined } }) let x = undefined;`, removing the initializer may affect lookup timing due to changes in when the binding is instantiated.
- In cases where the initializer contains a comment with a closing brace like `let x = undefined /* } */ ;`, moving the comment to the end of the statement could unintentionally comment out subsequent code if not properly wrapped.
- If the declaration is the sole content of a loop body like `for (; ;) let x = undefined;`, the fix results in `for (; ;) let x;` which is invalid because `let` declarations cannot appear directly in loop bodies without a block.
Programs
| id | result | title | hazard |
|---|---|---|---|
| r1-p001 | silent prediction off | null/undefined distinction affecting optional chaining | Removing `= undefined` changes initialization timing, causing optional chaining to short-circuit incorrectly due to ReferenceError instead of undefined. |
| r1-p002 | fix ok | Order of evaluation with comma operator and side effects | Removing initializer deletes a side-effect expression in a comma sequence, altering evaluation order and omitting a function call. |
| r1-p003 | fix ok | Comment displacement changing source meaning | Moving an inline comment after declaration alters its interpretation—here, turning a TODO into dead code via accidental line comment. |
| r1-p004 | fix ok | Strict mode error from undeclared variable due to early removal | In strict mode, removing initializer causes a temporary dead zone reference before declaration, throwing ReferenceError. |
Sources
r1-p001 · null/undefined distinction affecting optional chaining
1(() => {
2 let x;
3 if (typeof x === 'undefined') x = undefined; // Rule triggers
4 console.log((x?.prop || 'fallback'));
5})();
fallback
r1-p002 · Order of evaluation with comma operator and side effects
1(() => {
2 let log = [];
3 const f = v => { log.push(v); return v; };
4 let a = f(1), b = undefined, c = f(2); // Rule triggers on b
5 console.log(log.join(','));
6})();
--- orig.js 2026-10-17 19:44:11.634847476 -0400 +++ fixed.js 2026-10-17 19:44:11.797843208 -0400 @@ -1,6 +1,6 @@ (() => { let log = []; const f = v => { log.push(v); return v; }; - let a = f(1), b = undefined, c = f(2); // Rule triggers on b + let a = f(1), b , c = f(2); // Rule triggers on b console.log(log.join(',')); })();
1,2
r1-p003 · Comment displacement changing source meaning
1(() => {
2 let y = undefined; // TODO: initialize properly
3 console.log(y !== undefined ? 'set' : 'unset');
4})();
--- orig.js 2026-10-17 19:44:11.888840825 -0400 +++ fixed.js 2026-10-17 19:44:12.035836977 -0400 @@ -1,4 +1,4 @@ (() => { - let y = undefined; // TODO: initialize properly + let y ; // TODO: initialize properly console.log(y !== undefined ? 'set' : 'unset'); })();
unset
r1-p004 · Strict mode error from undeclared variable due to early removal
1"use strict";
2(() => {
3 console.log(typeof z); // Error if z not declared yet
4 let z = undefined; // Rule triggers
5 console.log(z);
6})();
--- orig.js 2026-10-17 19:44:12.121834725 -0400 +++ fixed.js 2026-10-17 19:44:12.264830982 -0400 @@ -1,6 +1,6 @@ "use strict"; (() => { console.log(typeof z); // Error if z not declared yet - let z = undefined; // Rule triggers + let z ; // Rule triggers console.log(z); })();