eslint sort-imports
labelled safe
Analysis Nemotron 3 Super
Enforces sorted import declarations by member syntax type and then by identifier name.
Fix: Reorders top-level import declarations so they are grouped by member syntax in the configured order (none, all, multiple, single) and sorted lexicographically within each group by the first imported identifier or alias; also sorts the members inside multiple-import braces alphabetically.
12 hazards
- Moving a side-effect-only import ('import "mod"') after another import may change execution order if the moved module depends on bindings from the later module.
- Placing a namespace import ('import * as ns') before a named import from the same module can cause a temporal dead zone if the named import is accessed during the namespace module's top-level execution.
- Swapping two named imports from different modules may break code if one module relies on a global side effect of the other that happens during its evaluation.
- Changing the order of imports can affect which duplicate binding wins in environments with non-strict or sloppy mode due to conflicting let/const/var declarations across modules.
- If an import is used in a dynamic import() expression later in the file, moving it earlier does not change behavior but moving it later could cause a reference error if the dynamic import relies on it being hoisted.
- Relocating an import that supplies a value used in a default export statement may temporarily leave the export undefined during module evaluation if the export statement runs before the import is moved.
- Altering import order can interfere with tools that rely on comment positioning for metadata (e.g., @ts-ignore, eslint-disable-next-line) if comments are attached to import lines and get reordered.
- In CommonJS interop scenarios, reordering ES imports may change the shape of the namespace object if the target module conditionally exports based on __dirname or process.argv evaluated at import time.
- Moving a type-only import (when using TypeScript's import type) after a value import from the same module may break if the type import was relied upon to avoid triggering side effects.
- If an import statement has an inline comment that affects tooling (e.g., // @ts-nocheck), moving that line may remove the comment's scope, altering type-checking behavior.
- Swapping imports can change the order of __esModule getter invocations when interoperating with default exports from CommonJS modules, potentially affecting which property is considered the default.
- If two modules define identically named bindings and the later one is moved before the former, any reference to that binding will now resolve to the earlier module's value, changing semantics.
Programs
| id | result | title | hazard |
|---|---|---|---|
| r1-p002 | invalid | async/await yields affected by import reorder | Swapping imports can affect the resolution timing of async modules, altering await order and generator yield positions. |
| r1-p003 | silent prediction off | __esModule getter invocation order changed | Swapping imports can change the order of __esModule getter invocations when interoperating with default exports from CommonJS modules, potentially affecting which property is considered the default. |
| r1-p004 | invalid | Import expression side effects duplicated or lost | Order of evaluation when expressions are merged, duplicated or deleted (side effects run twice or never) |
| r1-p005 | silent prediction off | Comments attached to moved import lost or misplaced | comments attached to the removed or moved code |
| r1-p006 | invalid | Var hoisting and re-declaration after import move | var hoisting and re-declaration inside loops or after use |
| r1-p007 | silent prediction off | Named import swap breaks global side-effect dependency | Swapping two named imports from different modules may break code if one module relies on a global side effect of the other that happens during its evaluation. |
| r1-p008 | fired, no fix | Sparse array construction affected by import order | sparse arrays, holes, Array(n) vs [n], array-likes |
| r2-p001 | silent prediction off | Temporal Dead Zone After Code Is Hoisted Or Reordered | temporal dead zone after code is hoisted or reordered |
| r2-p003 | invalid | Changing The Order Of Imports Can Affect Which Duplicate Binding Wins In Environments With Non-Strict Or Sloppy Mode Due | changing the order of imports can affect which duplicate binding wins in environments with non-strict or sloppy mode due to conflicting let/const/var declarations across modules. |
| r2-p004 | silent | Var Hoisting And Re-Declaration Inside Loops Or After Use | var hoisting and re-declaration inside loops or after use |
| r2-p005 | silent prediction off | In CommonJS Interop Scenarios, Reordering ES Imports May Change The Shape Of The Namespace Object If The Target Module C | in commonjs interop scenarios, reordering es imports may change the shape of the namespace object if the target module conditionally exports based on __dirname or process.argv evaluated at import time |
| r2-p006 | silent prediction off | Null/Undefined Distinction, Optional Chaining Short-Circuit, Nullish Vs Falsy | null/undefined distinction, optional chaining short-circuit, nullish vs falsy |
| r2-p007 | silent prediction off | If Two Modules Define Identically Named Bindings And The Later One Is Moved Before The Former, Any Reference To That Bin | if two modules define identically named bindings and the later one is moved before the former, any reference to that binding will now resolve to the earlier module's value, changing semantics. |
| r2-p008 | invalid | Function Declarations Inside Blocks, Switch Cases, Labeled Statements | function declarations inside blocks, switch cases, labeled statements |
Sources
r1-p002 · async/await yields affected by import reorder (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-22T18-31-4)
1// Hazard 2: async/await and generator interaction
2async function fetch() { return Promise.resolve(1); }
3import { fetch } from './async-mod'; // might be moved
4import * as gen from './generator-mod'; // has generator that yields after import
5(async () => {
6 const a = await fetch();
7 const it = gen.gen();
8 console.log(a, it.next().value);
9})();
r1-p003 · __esModule getter invocation order changed
1// Hazard 3: __esModule getter order
2let log = '';
3const originalDefineProperty = Object.defineProperty;
4Object.defineProperty = (obj, prop, desc) => {
5 if (prop === '__esModule' && desc.get) {
6 log += prop;
7 }
8 return originalDefineProperty.call(obj, prop, desc);
9};
10import cjs from './commonjs'; // triggers __esModule get
11import es from './es6'; // may be moved before it
12console.log(log);
r1-p004 · Import expression side effects duplicated or lost (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-22T18-31-4)
1// Hazard 4: Side effects in import specifiers
2let log = [];
3function sideEffect(x) { log.push(x); return x; }
4import { [sideEffect('a')]: foo } from './obj'; // may be moved
5import { bar } from './obj'; // may be moved
6console.log(log.join(','));
r1-p005 · Comments attached to moved import lost or misplaced
1// Hazard 5: Comment preservation
2// Keep this comment near b-import
3import a from './mod'; /* keep me */
4import b from './mod'; // TRIGGER: may be moved above a
5console.log('keep me' in a ? 1 : 0);
r1-p006 · Var hoisting and re-declaration after import move (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-22T18-31-4)
1// Hazard 6: Var hoisting and re-declaration
2if (true) {
3 var x = 1;
4}
5import { x } from './mod'; // TRIGGER: may be moved into block scope? No — top-level only.
6// But if moved before var x, it creates a TDZ-like error? Not in ES6.
7// Instead: re-declaration via import binding
8console.log(typeof x); // 'undefined' if import creates binding before var init
r1-p007 · Named import swap breaks global side-effect dependency
1// Hazard 7: Global side-effect dependency
2window.globalState = 0;
3import { triggerSideEffect } from './mod1'; // sets globalState = 42
4import { useSideEffect } from './mod2'; // reads globalState
5console.log(useSideEffect()); // should be 42, but if swapped, triggerSideEffect not run yet
r1-p008 · Sparse array construction affected by import order
1// Hazard 8: Sparse array and array-like confusion
2import { createArrayLike } from './arraylike'; // returns {0: 'a', length: 1}
3import { Array } from './array-shim'; // may override global Array
4const arr = createArrayLike();
5console.log(Array.isArray(arr)); // false if shimmed, true otherwise — depends on import order
r2-p001 · Temporal Dead Zone After Code Is Hoisted Or Reordered
1let y = undefined;
2if (!x) {
3 throw new Error('TDZ');
4}
5x = 1;
6y = 2;
7console.log(x);
8import { x } from './m1.js';
r2-p003 · Changing The Order Of Imports Can Affect Which Duplicate Binding Wins In Environments With Non-Strict Or Sloppy Mode Due (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-22T18-31-4)
1var z = 9;
2import { z } from './one.js'; // exports { z: 1 }
3{
4 console.log(z);
5 try { z = 2; } catch(e) { console.log(e.name); }
6}
r2-p004 · Var Hoisting And Re-Declaration Inside Loops Or After Use
1for (var i = 0; i < 2; i++) {
2 v = i;
3}
4v = 99;
5console.log(v);
6var v;
99
r2-p005 · In CommonJS Interop Scenarios, Reordering ES Imports May Change The Shape Of The Namespace Object If The Target Module C
1console.log(typeof ns.thing);
2ns.thing();
3import * as ns from './ns.js';
r2-p006 · Null/Undefined Distinction, Optional Chaining Short-Circuit, Nullish Vs Falsy
1let val = opts?.a?.b;
2console.log(val ?? 'missing');
3import { opts } from './cfg.js';
r2-p007 · If Two Modules Define Identically Named Bindings And The Later One Is Moved Before The Former, Any Reference To That Bin
1console.log(color);
2color = 'changed';
3import { color } from './theme.js'; // theme.js exports const color = 'blue'
r2-p008 · Function Declarations Inside Blocks, Switch Cases, Labeled Statements (generated program does not parse: /home/sun/dev/diaghunt/runs/2026-10-22T18-31-4)
1switch(1) {
2 case 1:
3 function g(){ return 1; }
4 console.log(g());
5 break;
6}
7try {
8 import { h } from './mod.js'; // mod.js does not export h
9} catch(e) {
10 console.log(e.code);
11}