fixhunt

eslint no-var

labelled safe
Runs / 2026-10-22T18-22-54-814Z-k9am-eslint-no-vareslint 9.39.52026-10-22 18:22 UTC8 programs × 2 round(s)15 programs, 13 fired, 6 fixed, 0 findings, 2 rejectedmodel cost $0.0034

Analysis Nemotron 3 Super

The rule flags any declaration using the `var` keyword and suggests replacing it with `let` or `const`.

Fix: Replace `var` with `let` when the variable is reassigned, otherwise replace with `const`.

12 hazards
  • Changing `var` to `let` in a function-scoped variable accessed before declaration causes a ReferenceError due to TDZ, whereas `var` would be undefined.
  • Replacing `var` with `let` in a loop variable used in a closure captures the block-scoped value per iteration, altering behavior if closures were meant to share the same variable.
  • Converting `var` to `const` fails if the variable is later reassigned, causing a runtime error where the original code would have succeeded.
  • Moving a `var` declaration to block scope via `let`/`const` can break code that relied on function-scoped hoisting across conditional blocks.
  • In sloppy mode, `var` can create a global variable if not in a function scope; replacing with `let`/`const` prevents this, potentially breaking implicit globals.
  • In strict mode, `var` and `let`/`const` both avoid implicit globals, but `let`/`const` in a block may not be accessible where hoisted `var` was, breaking access.
  • If a `var` declaration is inside a `with` statement, replacing it with `let`/`const` is invalid syntax and will throw a SyntaxError.
  • Comments attached to the `var` keyword or declaration may be lost or misplaced during the rewrite, especially if the fix tool does not preserve comment tokens.
  • In TypeScript ambient contexts like `declare var`, replacing with `let`/`const` is invalid and will cause a compilation error, as only `var` is allowed in certain declaration spaces.
  • When `var` is used in a `for`-loop initializer with a comma-separated declaration, the fix may incorrectly scope only part of the declaration, leading to syntax errors or unintended behavior.
  • If `var` is used to declare a function parameter name in a destructuring default (non-standard), the rewrite could break parsing or alter evaluation semantics.
  • In eval() contexts, changing `var` to `let`/`const` alters the scope of the evaluated code, potentially leaking or containing variables differently than expected.

Programs

idresulttitlehazard
r1-p001invalidVar Inside With StatementIf a `var` declaration is inside a `with` statement, replacing it with `let`/`const` is invalid syntax and will throw a SyntaxError.
r1-p002fix okTypeScript Ambient Context - declare varIn TypeScript ambient contexts like `declare var`, replacing with `let`/`const` is invalid and will cause a compilation error, as only `var` is allowed in certain declaration spaces.
r1-p003fired, no fixASI and Leading Parenthesis After Var DeclarationASI and semicolon-less code, leading ( or [ on the next line
r1-p004fix okSparse Arrays and Array Constructor Ambiguitysparse arrays, holes, Array(n) vs [n], array-likes
r1-p005fired, no fixTemporal Dead Zone After Hoisting Reordertemporal dead zone after code is hoisted or reordered
r1-p006fix okComments Attached to Var Keyword Lost During RewriteComments attached to the `var` keyword or declaration may be lost or misplaced during the rewrite, especially if the fix tool does not preserve comment tokens.
r1-p008fix okEval Scope Leakage When Var Changed to LetIn eval() contexts, changing `var` to `let`/`const` alters the scope of the evaluated code, potentially leaking or containing variables differently than expected.
r2-p001fired, no fixLoop Closure Variable CaptureReplacing `var` with `let` in a loop variable used in a closure captures the block-scoped value per iteration, altering behavior if closures were meant to share the same variable.
r2-p002fix okComment Preservation on Var KeywordComments attached to the `var` keyword or declaration may be lost or misplaced during the rewrite, especially if the fix tool does not preserve comment tokens.
r2-p003fired, no fixStrict Mode Block Scope AccessibilityIn strict mode, `var` and `let`/`const` both avoid implicit globals, but `let`/`const` in a block may not be accessible where hoisted `var` was, breaking access.
r2-p004fix okArguments Object and Parameter Interactionarguments object, function.length, default parameters, rest parameters
r2-p005fired, no fixConditional Block Hoisting RelianceMoving a `var` declaration to block scope via `let`/`const` can break code that relied on function-scoped hoisting across conditional blocks.
r2-p006fired, no fixTemporal Dead Zone After Hoistingtemporal dead zone after code is hoisted or reordered
r2-p007invalidASI and Semicolon-less Leading ParenthesisASI and semicolon-less code, leading ( or [ on the next line
r2-p008fired, no fixFor-Loop Comma-Separated Declaration ScopingWhen `var` is used in a `for`-loop initializer with a comma-separated declaration, the fix may incorrectly scope only part of the declaration, leading to syntax errors or unintended behavior.

Sources

r1-p001 · Var Inside With Statement (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-22T18-22-5)
1(function () {
2 'use strict';
3 const obj = {x: 42};
4 try {
5 with (obj) {
6 // var x /* scoped comment */ ;
7 var x = 99;
8 }
9 console.log(obj.x); // prints original value
10 } catch (e) {
11 console.log(e.name + ': ' + e.message);
12 }
13})();
r1-p002 · TypeScript Ambient Context - declare var
1// @ts-ignore
2// This simulates TS ambient context via comment-triggered rewrite risk
3/* declare */ var globalValue = 123;
4console.log(typeof globalValue === 'number' ? globalValue : 'invalid');
--- orig.js	2026-10-22 14:23:04.775235294 -0400
+++ fixed.js	2026-10-22 14:23:09.035419352 -0400
@@ -1,4 +1,4 @@
 // @ts-ignore
 // This simulates TS ambient context via comment-triggered rewrite risk
-/* declare */ var globalValue = 123;
+/* declare */ let globalValue = 123;
 console.log(typeof globalValue === 'number' ? globalValue : 'invalid');
123
r1-p003 · ASI and Leading Parenthesis After Var Declaration
1(function () {
2 var a = 1
3 (function () {
4 console.log('IIFE executed:', a)
5 })()
6 return a
7})()
r1-p004 · Sparse Arrays and Array Constructor Ambiguity
1(function () {
2 var arr = Array(3); // creates [empty × 3]
3 arr[0] = 'a';
4 arr[2] = 'c';
5 console.log(arr.length, arr.join(':'));
6 var len = arr.length;
7 console.log(len);
8})()
--- orig.js	2026-10-22 14:23:04.776235337 -0400
+++ fixed.js	2026-10-22 14:23:07.947372323 -0400
@@ -1,8 +1,8 @@
 (function () {
-  var arr = Array(3); // creates [empty × 3]
+  let arr = Array(3); // creates [empty × 3]
   arr[0] = 'a';
   arr[2] = 'c';
   console.log(arr.length, arr.join(':'));
-  var len = arr.length;
+  let len = arr.length;
   console.log(len);
 })()
3 a::c
3
r1-p005 · Temporal Dead Zone After Hoisting Reorder
1(function () {
2 console.log(typeof x); // 'undefined' due to hoisting
3 var x = 1;
4 try {
5 console.log(y); // ReferenceError if let/const
6 var y = 2;
7 } catch (e) {
8 console.log(e.name + ': ' + e.message);
9 }
10 console.log(x, y);
11})()
undefined
undefined
1 2
r1-p006 · Comments Attached to Var Keyword Lost During Rewrite
1(function () {
2 // var counter /* inline comment */ = 0;
3 var counter /* inline comment */ = 0;
4 (function inner() {
5 counter++;
6 console.log(counter);
7 })();
8 console.log(counter);
9})()
--- orig.js	2026-10-22 14:23:04.777235380 -0400
+++ fixed.js	2026-10-22 14:23:07.390348253 -0400
@@ -1,6 +1,6 @@
 (function () {
   // var counter /* inline comment */ = 0;
-  var counter /* inline comment */ = 0;
+  let counter /* inline comment */ = 0;
   (function inner() {
     counter++;
     console.log(counter);
1
1
r1-p008 · Eval Scope Leakage When Var Changed to Let
1(function () {
2 var globalInEval = 100;
3 eval('var localInEval = 200; console.log(typeof globalInEval, typeof localInEval);');
4 try {
5 console.log(typeof globalInEval, typeof localInEval); // localInEval leaked if var
6 } catch (e) {
7 console.log(e.name + ': ' + e.message);
8 }
9})()
--- orig.js	2026-10-22 14:23:04.806236632 -0400
+++ fixed.js	2026-10-22 14:23:08.572399338 -0400
@@ -1,5 +1,5 @@
 (function () {
-  var globalInEval = 100;
+  let globalInEval = 100;
   eval('var localInEval = 200; console.log(typeof globalInEval, typeof localInEval);');
   try {
     console.log(typeof globalInEval, typeof localInEval); // localInEval leaked if var
number number
number number
r2-p001 · Loop Closure Variable Capture
1function test() {
2 const funcs = [];
3 for (var i = 0; i < 3; i++) {
4 funcs.push(() => i);
5 }
6 return funcs.map(f => f());
7}
8console.log(test().join(','));
3,3,3
r2-p002 · Comment Preservation on Var Keyword
1// This is before
2/* inline */ var /* comment */ x /* end */ = 1;
3// After fix, comment placement may break
4if (typeof x === 'number') {
5 console.log('ok:', x);
6} else {
7 console.log('fail');
8}
--- orig.js	2026-10-22 14:23:16.759753644 -0400
+++ fixed.js	2026-10-22 14:23:20.537917415 -0400
@@ -1,5 +1,5 @@
 // This is before
-/* inline */ var /* comment */ x /* end */ = 1;
+/* inline */ let /* comment */ x /* end */ = 1;
 // After fix, comment placement may break
 if (typeof x === 'number') {
   console.log('ok:', x);
ok: 1
r2-p003 · Strict Mode Block Scope Accessibility
1"use strict";
2if (true) {
3 var x = 1;
4}
5try {
6 console.log(x); // Should work with var hoisting
7} catch (e) {
8 console.log(e.name + ': ' + e.message);
9}
1
r2-p004 · Arguments Object and Parameter Interaction
1function f(a, b = 2) {
2 var argumentsLength = arguments.length;
3 if (typeof arguments === 'object' && !(arguments instanceof Array)) {
4 return argumentsLength + (b || 0);
5 }
6 return -1;
7}
8console.log(f(1, 3) + ',' + f(1));
--- orig.js	2026-10-22 14:23:16.760753688 -0400
+++ fixed.js	2026-10-22 14:23:19.993893821 -0400
@@ -1,5 +1,5 @@
 function f(a, b = 2) {
-  var argumentsLength = arguments.length;
+  let argumentsLength = arguments.length;
   if (typeof arguments === 'object' && !(arguments instanceof Array)) {
     return argumentsLength + (b || 0);
   }
5,3
r2-p005 · Conditional Block Hoisting Reliance
1function test() {
2 if (false) {
3 var x = 1;
4 } else {
5 return typeof x === 'undefined' ? 'undef' : x; // x hoisted, accessible
6 }
7}
8console.log(test());
undef
r2-p006 · Temporal Dead Zone After Hoisting
1function test() {
2 console.log(typeof x); // With var: undefined; with let: TDZ error
3 var x = 1;
4 return x;
5}
6try {
7 console.log(test());
8} catch (e) {
9 console.log(e.name + ': ' + e.message);
10}
undefined
1
r2-p007 · ASI and Semicolon-less Leading Parenthesis (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-22T18-22-5)
1var x = 1
2(function(){
3 return x;
4})()
5// After fix: let x = 1
6(function(){...})() still works, but if ASI breaks due to comment loss...
7// We make it depend on comment-attached var
8/* start */ var /* mid */ y = 2 /* end */
9[3,4].forEach(v => console.log(v + y));
r2-p008 · For-Loop Comma-Separated Declaration Scoping
1function test() {
2 for (var i = 0, j = 10; i < 3; i++, j--) {
3 // j must be function-scoped to be accessible after loop
4 }
5 return typeof j !== 'undefined' ? j : 'undef';
6}
7console.log(test());
7