eslint/rules/variables
Variables: Declarations, scope, shadowing, assignments and destructuring. Rules of ESLint, typescript-eslint and SonarJS (the Sonar way profile of SonarQube) on this subject, every rule listed; the TypeScript rules apply to TypeScript files only.
55 rules, 30 on. Source: lint/eslint/rules/variables.mjs.
| Rule | Setting | Files | What it checks | Why |
|---|---|---|---|---|
no-const-assign | error | JS + TS | Disallow reassigning const, using, and await using variables | — |
no-dupe-args | error | JS + TS | Disallow duplicate arguments in function definitions | — |
no-inner-declarations | error | JS + TS | Disallow variable or function declarations in nested blocks | — |
no-unassigned-vars | error | JS + TS | Disallow let or var variables that are read but never assigned | — |
no-undef | error | JS + TS | Disallow the use of undeclared variables unless mentioned in /*global */ comments | — |
no-unused-vars | error | JS + TS | Disallow unused variables | Replaced by the TS version. |
no-use-before-define | error | JS + TS | Disallow the use of variables before they are defined | Replaced by the TS version. |
block-scoped-var | warn | JS + TS | Enforce the use of variables within the scope they are defined | — |
init-declarations | off | JS + TS | Require or disallow initialization in variable declarations | Off: non-standard, forbids let x: T; assigned later. |
no-delete-var | warn | JS + TS | Disallow deleting variables | — |
no-global-assign | error | JS + TS | Disallow assignments to native objects or read-only global variables | — |
no-implicit-globals | error | JS + TS | Disallow declarations in the global scope | — |
no-multi-assign | info, {"ignoreNonDeclaration":true} | JS + TS | Disallow use of chained assignment expressions | a = b = 0 is allowed, const a = (b = 0) is not. |
no-redeclare | error | JS + TS | Disallow variable redeclaration | Replaced by the TS version (a type and a value may not share a name either). |
no-restricted-globals | off | JS + TS | Disallow specified global variables | — |
no-shadow | warn | JS + TS | Disallow variable declarations from shadowing variables declared in the outer scope | Replaced by the TS version. |
no-undef-init | off | JS + TS | Disallow initializing variables to undefined | — |
no-useless-rename | error | JS + TS | Disallow renaming import, export, and destructured assignments to the same name | — |
no-var | error | JS + TS | Require let or const instead of var | — |
no-with | error | JS + TS | Disallow with statements | — |
one-var | error, "never" | JS + TS | Enforce variables to be declared either together or separately in functions | One declaration per statement (cleaner diffs). |
prefer-const | error, {"destructuring":"all"} | JS + TS | Require const declarations for variables that are never reassigned after declared | Destructuring is reported only when every variable could be const. |
prefer-destructuring | error | JS + TS | Require destructuring from arrays and/or objects | Replaced by the TS version. |
vars-on-top | off | JS + TS | Require var declarations be placed at the top of their containing scope | Off: var is forbidden (no-var). |
sonarjs/destructuring-assignment-syntax | off | JS + TS | Destructuring syntax should be used for assignments | Off: not in the Sonar way profile of SonarQube. |
sonarjs/block-scoped-var | off | JS + TS | Variables should be used in the blocks where they are declared | Off: duplicate of block-scoped-var. |
sonarjs/no-delete-var | off | JS + TS | "delete" should be used only with object properties | Off: duplicate of no-delete-var. |
sonarjs/no-globals-shadowing | off | JS + TS | Special identifiers should not be bound or assigned | Off: duplicate of no-shadow-restricted-names. |
sonarjs/no-implicit-global | off | JS + TS | Variables should be declared explicitly | Off: duplicate of no-undef (and a TypeScript compiler error). |
sonarjs/no-unused-vars | off | JS + TS | Unused local variables and functions should be removed | Off: duplicate of @typescript-eslint/no-unused-vars (which honours the _ prefix). |
sonarjs/declarations-in-global-scope | off | JS + TS | Variables and functions should not be declared in the global scope | Off: not in the Sonar way profile of SonarQube. |
sonarjs/no-mixed-completion-style | off | JS + TS | Test and hook callbacks should use a single completion style | Off: not in the Sonar way profile of SonarQube. |
sonarjs/no-nested-assignment | warn | JS + TS | Assignments should not be made from within sub-expressions | — |
sonarjs/no-redundant-assignments | warn | JS + TS | Assignments should not be redundant | — |
sonarjs/no-variable-usage-before-declaration | off | JS + TS | Variables declared with "var" should be declared before they are used | Off: not in the Sonar way profile of SonarQube. |
no-const-assign | off | TS | Disallow reassigning const, using, and await using variables | — |
no-dupe-args | off | TS | Disallow duplicate arguments in function definitions | — |
no-undef | off | TS | Disallow the use of undeclared variables unless mentioned in /*global */ comments | — |
no-with | off | TS | Disallow with statements | — |
no-delete-var | off | TS | Disallow deleting variables | — |
no-implicit-globals | off | TS | Disallow declarations in the global scope | — |
@typescript-eslint/init-declarations | off | TS | Require or disallow initialization in variable declarations | Off: see core rule. If enabled, write ['error', 'always'] (ESLint 10 passes no default mode). |
@typescript-eslint/no-dynamic-delete | warn | TS | Disallow using the delete operator on computed key expressions | — |
no-redeclare | off | TS | Disallow variable redeclaration | Replaced by the TS version (a type and a value may not share a name either). |
@typescript-eslint/no-redeclare | error, {"ignoreDeclarationMerge":false} | TS | Disallow variable redeclaration | — |
no-shadow | off | TS | Disallow variable declarations from shadowing variables declared in the outer scope | Replaced by the TS version. |
@typescript-eslint/no-shadow | warn | TS | Disallow variable declarations from shadowing variables declared in the outer scope | — |
no-unused-vars | off | TS | Disallow unused variables | Replaced by the TS version. |
@typescript-eslint/no-unused-vars | error, {"argsIgnorePattern":"^_","varsIgnorePattern":"^_","caugh… | TS | Disallow unused variables | _ prefix = intentionally unused. |
no-use-before-define | off | TS | Disallow the use of variables before they are defined | Replaced by the TS version. |
@typescript-eslint/no-use-before-define | error, {"functions":false} | TS | Disallow the use of variables before they are defined | Hoisted function declarations may be used before their definition. |
@typescript-eslint/no-useless-default-assignment | info | TS | Disallow default values that will never be used | — |
@typescript-eslint/prefer-as-const | error | TS | Enforce the use of as const over literal type | — |
prefer-destructuring | off | TS | Require destructuring from arrays and/or objects | Replaced by the TS version. |
@typescript-eslint/prefer-destructuring | error | TS | Require destructuring from arrays and/or objects | — |