shadowed-variable
What it does
Section titled “What it does”Reports a variable, parameter or function with the name of one declared in a scope around it. A function declared later in the outer scope still counts (it is hoisted), a variable declared later does not, and var a = function a() {} is not a shadow. In TypeScript files a type and a value of one name, and the parameters of function types, are not reported.
Why it matters
Section titled “Why it matters”The inner name hides the outer one for the rest of its scope, so the same word means two things, and a change that was meant for the outer variable lands on the inner one or the reverse.
To fix, rename the inner variable.
Example
Section titled “Example”var a = 1; let b = 2;function f(a) { let b = 3; { const a = 4; } }var c = function c() {}; var d = function (d) {};function outer() { var e = 1; function inner() { var e = 2; } }function hoist() { var h = 1; } function h() {}const t = () => { const late = 1; }; const late = 2;class K { m() { var K = 1; } }Configuration
Section titled “Configuration”js: lint: rules: shadowed-variable: level: warn # off (default), warn, error options: allow: [] kinds: []python: lint: rules: shadowed-variable: level: warn # off (default), warn, error options: allow: [] kinds: []| Option | Type | Default | Description |
|---|---|---|---|
allow |
list | [] |
Names that may shadow. |
kinds |
list | [] |
The declarations that are checked for shadowing something (empty: all). Values: variable, parameter, function, class, import, type |
Enabled by the presets: python/ruff.
Suppress one line with sudsy-disable-next-line shadowed-variable in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| eslint | no-shadow |
partial | the options keep their defaults (builtinGlobals off, hoist functions, allow empty, ignoreOnInitialization off) |
| ruff | F402 |
full | |
| ruff | PLR1704 |
full | |
| typescript-eslint | no-shadow |
partial | the options keep their defaults |