fixhunt

biome complexity/noUselessUndefinedInitialization: fix changes program behavior

fix-changes-behaviorlabelled safereal · highduplicate
Findings / 2026-10-17T20-10-15-247Z-vb8k-biome-complexity_noUselessUndefinedInitialization / r1-p007biome 2.5.1515 → 8 lines2026-10-17 20:10 UTC

Hypothesis Nemotron 3 Super predicted to fire fired 1×

In a comma-separated declaration like `var a = undefined, b = 1;`, removing `= undefined` results in `var a, b = 1;`, which is valid and equivalent because `a` is still implicitly `undefined`.

Program

before
1function commaTest() {
2 a = 'assigned';
3 if (true) {
4 var a = undefined, c = 2; // Rule triggers again
5 }
6 console.log('After redeclaration:', a, typeof c);
7}
8commaTest();
after
1function commaTest() {
2 a = 'assigned';
3 if (true) {
4 var a , c = 2; // Rule triggers again
5 }
6 console.log('After redeclaration:', a, typeof c);
7}
8commaTest();

Output

stdout beforeexit 0
After redeclaration: undefined number
stdout afterexit 0
After redeclaration: assigned number
fired
1 before · 0 after
runs
each version twice, same file name, no network

Judge Nemotron 3 Ultra advisory real · high

The fix removes the explicit `= undefined` initializer from a `var` declaration inside a block, but `var` is function-scoped and hoisted. The original code re-initialized the function-scoped `a` to `undefined` when the block executed, overwriting the earlier assignment `a = 'assigned'`. After the fix, the declaration becomes `var a` with no initializer, which does not re-assign `a` at runtime, so the outer assignment persists and the program prints `assigned` instead of `undefined`. The documentation presents the rewrite as equivalent, but for function-scoped `var` the initializer has observable runtime effect, making the fix unsafe for this construct.

Explanation Nemotron 3 Super unverified

The original declaration `var a = undefined` initializes variable `a` to `undefined`, overriding its prior value `'assigned'` due to hoisting within the same scope. Removing `= undefined` leaves `a` uninitialized initially but still redeclared via `var`, so it retains the outer assignment’s value `'assigned'`. Thus `console.log` outputs different values for `a`. This change alters observable behavior, violating semantic preservation.

Reproduce

file
prog.js (the before program)
minimized program
r1-p007.js
evidence sheet
r1-p007.md
regression fixture
r1-p007.js the minimized program with a header stating the observed change, for the tool's test suite
node prog.js
bunx @biomejs/biome lint --only=complexity/noUselessUndefinedInitialization --write prog.js
node prog.js

Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra

noUselessUndefinedInitialization fix · complexity noUselessUndefinedInitialization variable declaration · var initialization redundant undefined assignment · block-scoped variable shadowing outer scope

Details

program
Comma-Separated Declaration Equivalence
hazard
In a comma-separated declaration like `var a = undefined, b = 1;`, removing `= undefined` results in `var a, b = 1;`, which is valid and equivalent because `a` is still implicitly `undefined`.
oracle
stdout before: After redeclaration: undefined number stdout after: After redeclaration: assigned number
run
2026-10-17T20-10-15-247Z-vb8k-biome-complexity_noUselessUndefinedInitialization
generated program (15 lines) and the fix's diff
1function commaTest() {
2 var a = undefined, b = 1; // Rule triggers on a
3 console.log('Initial:', typeof a, b);
4 a = 'assigned';
5 console.log('After reassignment:', a, b);
6
7 // Re-enter scope to test re-declaration
8 if (true) {
9 var a = undefined, c = 2; // Rule triggers again
10 console.log('Redecled:', a, c);
11 }
12 console.log('After redeclaration:', a, typeof c);
13}
14
15commaTest();
--- orig.js	2026-10-17 16:10:29.950350814 -0400
+++ fixed.js	2026-10-17 16:10:30.215343061 -0400
@@ -1,12 +1,12 @@
 function commaTest() {
-  var a = undefined, b = 1; // Rule triggers on a
+  var a , b = 1; // Rule triggers on a
   console.log('Initial:', typeof a, b);
   a = 'assigned';
   console.log('After reassignment:', a, b);
   
   // Re-enter scope to test re-declaration
   if (true) {
-    var a = undefined, c = 2; // Rule triggers again
+    var a , c = 2; // Rule triggers again
     console.log('Redecled:', a, c);
   }
   console.log('After redeclaration:', a, typeof c);
rule documentation given to the models
Summary

- Name: noUselessUndefinedInitialization
- Fix: safe
- Default severity: info
- Available from version: 1.7.2
- Diagnostic category: lint/complexity/noUselessUndefinedInitialization
- This rule is recommended

Description

 Disallow initializing variables to `undefined`.

 A variable that is declared and not initialized to any value automatically gets the value of `undefined`.
 It’s considered a best practice to avoid initializing variables to `undefined`.

 Please note that any inline comments attached to the initialization value or variable will be moved at the end of the variable declaration on auto-fix.
 Please be also aware that this differs from Eslint's behaviour.

Examples

Invalid

 ```js,expect_diagnostic
 var a = undefined;
 ```
 ```js,expect_diagnostic
 let b = undefined, c = 1, d = 2;
 ```
 ```js,expect_diagnostic
 for (let i = 0; i < 100; i++) {
 	let i = undefined;
 }
 ```
 ```js,expect_diagnostic
 let f = /**/undefined/**/ ;
 ```
Valid

 ```js
 var a = 1;
 ```
 ```js
 class Foo {
 	bar = undefined;
 }
 ```

 Exported variables are not flagged because in some frameworks (e.g., Svelte 4),
 initializing exported variables to `undefined` is used to declare optional props.

 ```js
 export let x = undefined;
 ```
 ```js
 let y = undefined;
 export { y };
 ```