Skip to main content

What it flags

A var declaration, including for (var ...), in an ES module (a file with import or export), a .mjs, .cjs, .mts or .cts file, or inside a function in any TypeScript file. var is function-scoped and hoisted, so the name leaks out of its block and loop and can be read before it is assigned. Each declaration list is reported once. It stays quiet for declare var and declare global { var ... }, which describe globals; for top-level var in a TypeScript script that is not a module, where the name is a global other scripts may read; for plain .js scripts that are not modules, which may target older runtimes; for a top-level var in a test, which vi.mock and jest.mock factories rely on being hoisted; for lines where ESLint’s no-var is switched off, including a file-wide /* eslint-disable */ over copied code; for lines over 300 characters, which are minified or obfuscated; and for declaration files, build output such as dist-js/, bundled libraries, generated and vendored code.

How to review

Use const, or let when the variable is reassigned. Check that no code reads the name before its declaration or outside the block it now belongs to, since let and const throw or are out of scope there. There is no automatic fix.

Configuration

Set the rule to "off" in loadwise.config.json to drop its findings: