Skip to content

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.

RuleSettingFilesWhat it checksWhy
no-const-assignerrorJS + TSDisallow reassigning const, using, and await using variables—
no-dupe-argserrorJS + TSDisallow duplicate arguments in function definitions—
no-inner-declarationserrorJS + TSDisallow variable or function declarations in nested blocks—
no-unassigned-varserrorJS + TSDisallow let or var variables that are read but never assigned—
no-undeferrorJS + TSDisallow the use of undeclared variables unless mentioned in /*global */ comments—
no-unused-varserrorJS + TSDisallow unused variablesReplaced by the TS version.
no-use-before-defineerrorJS + TSDisallow the use of variables before they are definedReplaced by the TS version.
block-scoped-varwarnJS + TSEnforce the use of variables within the scope they are defined—
init-declarationsoffJS + TSRequire or disallow initialization in variable declarationsOff: non-standard, forbids let x: T; assigned later.
no-delete-varwarnJS + TSDisallow deleting variables—
no-global-assignerrorJS + TSDisallow assignments to native objects or read-only global variables—
no-implicit-globalserrorJS + TSDisallow declarations in the global scope—
no-multi-assigninfo, {"ignoreNonDeclaration":true}JS + TSDisallow use of chained assignment expressionsa = b = 0 is allowed, const a = (b = 0) is not.
no-redeclareerrorJS + TSDisallow variable redeclarationReplaced by the TS version (a type and a value may not share a name either).
no-restricted-globalsoffJS + TSDisallow specified global variables—
no-shadowwarnJS + TSDisallow variable declarations from shadowing variables declared in the outer scopeReplaced by the TS version.
no-undef-initoffJS + TSDisallow initializing variables to undefined—
no-useless-renameerrorJS + TSDisallow renaming import, export, and destructured assignments to the same name—
no-varerrorJS + TSRequire let or const instead of var—
no-witherrorJS + TSDisallow with statements—
one-varerror, "never"JS + TSEnforce variables to be declared either together or separately in functionsOne declaration per statement (cleaner diffs).
prefer-consterror, {"destructuring":"all"}JS + TSRequire const declarations for variables that are never reassigned after declaredDestructuring is reported only when every variable could be const.
prefer-destructuringerrorJS + TSRequire destructuring from arrays and/or objectsReplaced by the TS version.
vars-on-topoffJS + TSRequire var declarations be placed at the top of their containing scopeOff: var is forbidden (no-var).
sonarjs/destructuring-assignment-syntaxoffJS + TSDestructuring syntax should be used for assignmentsOff: not in the Sonar way profile of SonarQube.
sonarjs/block-scoped-varoffJS + TSVariables should be used in the blocks where they are declaredOff: duplicate of block-scoped-var.
sonarjs/no-delete-varoffJS + TS"delete" should be used only with object propertiesOff: duplicate of no-delete-var.
sonarjs/no-globals-shadowingoffJS + TSSpecial identifiers should not be bound or assignedOff: duplicate of no-shadow-restricted-names.
sonarjs/no-implicit-globaloffJS + TSVariables should be declared explicitlyOff: duplicate of no-undef (and a TypeScript compiler error).
sonarjs/no-unused-varsoffJS + TSUnused local variables and functions should be removedOff: duplicate of @typescript-eslint/no-unused-vars (which honours the _ prefix).
sonarjs/declarations-in-global-scopeoffJS + TSVariables and functions should not be declared in the global scopeOff: not in the Sonar way profile of SonarQube.
sonarjs/no-mixed-completion-styleoffJS + TSTest and hook callbacks should use a single completion styleOff: not in the Sonar way profile of SonarQube.
sonarjs/no-nested-assignmentwarnJS + TSAssignments should not be made from within sub-expressions—
sonarjs/no-redundant-assignmentswarnJS + TSAssignments should not be redundant—
sonarjs/no-variable-usage-before-declarationoffJS + TSVariables declared with "var" should be declared before they are usedOff: not in the Sonar way profile of SonarQube.
no-const-assignoffTSDisallow reassigning const, using, and await using variables—
no-dupe-argsoffTSDisallow duplicate arguments in function definitions—
no-undefoffTSDisallow the use of undeclared variables unless mentioned in /*global */ comments—
no-withoffTSDisallow with statements—
no-delete-varoffTSDisallow deleting variables—
no-implicit-globalsoffTSDisallow declarations in the global scope—
@typescript-eslint/init-declarationsoffTSRequire or disallow initialization in variable declarationsOff: see core rule. If enabled, write ['error', 'always'] (ESLint 10 passes no default mode).
@typescript-eslint/no-dynamic-deletewarnTSDisallow using the delete operator on computed key expressions—
no-redeclareoffTSDisallow variable redeclarationReplaced by the TS version (a type and a value may not share a name either).
@typescript-eslint/no-redeclareerror, {"ignoreDeclarationMerge":false}TSDisallow variable redeclaration—
no-shadowoffTSDisallow variable declarations from shadowing variables declared in the outer scopeReplaced by the TS version.
@typescript-eslint/no-shadowwarnTSDisallow variable declarations from shadowing variables declared in the outer scope—
no-unused-varsoffTSDisallow unused variablesReplaced by the TS version.
@typescript-eslint/no-unused-varserror, {"argsIgnorePattern":"^_","varsIgnorePattern":"^_","caugh…TSDisallow unused variables_ prefix = intentionally unused.
no-use-before-defineoffTSDisallow the use of variables before they are definedReplaced by the TS version.
@typescript-eslint/no-use-before-defineerror, {"functions":false}TSDisallow the use of variables before they are definedHoisted function declarations may be used before their definition.
@typescript-eslint/no-useless-default-assignmentinfoTSDisallow default values that will never be used—
@typescript-eslint/prefer-as-consterrorTSEnforce the use of as const over literal type—
prefer-destructuringoffTSRequire destructuring from arrays and/or objectsReplaced by the TS version.
@typescript-eslint/prefer-destructuringerrorTSRequire destructuring from arrays and/or objects—

Generated from the JSDoc of the sources.