fixhunt

biome complexity/noUselessUndefinedInitialization: fix changes program behavior

fix-changes-behaviorlabelled safereal · highrelated
Findings / 2026-10-17T20-10-15-247Z-vb8k-biome-complexity_noUselessUndefinedInitialization / r2-p002biome 2.5.156 → 5 lines2026-10-17 20:10 UTC

Hypothesis Nemotron 3 Super predicted to fire fired 1×

In non-strict mode, a variable named `undefined` could be reassigned, but the rule only flags explicit initialization to the literal `undefined`, so the fix remains safe as it doesn't affect the globa

Program

before
1(function() {
2 var undefined = 42;
3 var x = undefined;
4 console.log(x);
5})();
after
1(function() {
2 var undefined = 42;
3 var x ;
4 console.log(x);
5})();

Output

stdout beforeexit 0
42
stdout afterexit 0
undefined
fired
1 before · 0 after
runs
each version twice, same file name, no network

Judge Nemotron 3 Ultra advisory real · high

The rule assumes the global `undefined` binding, but the program shadows `undefined` with a local variable holding 42. The fix removes the initializer, changing `x` from 42 to the real `undefined`, which is a silent wrong result in plausible code.

Explanation Nemotron 3 Super unverified

The original declaration `var undefined = 42` creates a local variable named `undefined`, shadowing the global property; thus `x` receives the value 42. After rewriting to `var x ;`, `x` is declared but never initialized, so it holds the initial value of uninitialized variables—`undefined`. Consequently `console.log(x)` outputs `undefined` instead of `42`, changing observable behavior.

Reproduce

file
prog.js (the before program)
minimized program
r2-p002.js
evidence sheet
r2-p002.md
regression fixture
r2-p002.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 · Biome lint rule useless undefined initialization shadowing global · fix removes redundant assignment to shadowed undefined variable

Details

program
Non-Strict Mode Undefined Reassignment Safety
hazard
In non-strict mode, a variable named `undefined` could be reassigned, but the rule only flags explicit initialization to the literal `undefined`, so the fix remains safe as it doesn't affect the globa
oracle
stdout before: 42 stdout after: undefined
run
2026-10-17T20-10-15-247Z-vb8k-biome-complexity_noUselessUndefinedInitialization
generated program (6 lines) and the fix's diff
1(function() {
2 'use sloppy';
3 var undefined = 42;
4 var x = undefined;
5 console.log(x);
6})();
--- orig.js	2026-10-17 16:10:34.886207085 -0400
+++ fixed.js	2026-10-17 16:10:35.161199124 -0400
@@ -1,6 +1,6 @@
 (function() {
   'use sloppy';
   var undefined = 42;
-  var x = undefined;
+  var x ;
   console.log(x);
 })();
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 };
 ```