no-shadow
Disallow shadowing variables from outer scopes.
Targeted pattern scopeโ
This rule walks lexical scopes and reports variable declarations that reuse names from parent scopes.
Enum declarations are intentionally ignored.
What this rule reportsโ
This rule reports variables that reuse names from outer scopes.
Enum declarations are skipped both when evaluating the current declaration and when evaluating potential outer-scope matches.
Why this rule existsโ
Shadowing can hide outer bindings and make data flow harder to reason about.
โ Incorrectโ
const x = 1;
function f() {
const x = 2;
return x;
}
โ Correctโ
const x = 1;
function f() {
const y = x + 1;
return y;
}
Deprecatedโ
- Lifecycle: Deprecated and frozen.
- Deprecated since:
v1.0.0 - Available until:
v2.0.0 - Use instead:
@typescript-eslint/no-shadow
Behavior and migration notesโ
This rule is deprecated in favor of @typescript-eslint/no-shadow.
It reports only and does not provide an autofix.
Optionsโ
This rule has no options.
Statusโ
Use the Deprecated section above for lifecycle details.
Additional examplesโ
enum Status {
Ready,
}
function run(Status: number): number {
return Status;
}
// enum-related declarations are intentionally ignored by this rule.
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-shadow": "error",
},
},
];
When not to use itโ
Disable this rule if shadowed variable names are acceptable in your code style.
Package documentationโ
Rule catalog ID: R040
Further readingโ
Adoption resourcesโ
- Start at warning level in CI, then move to error after cleanup.
- Use focused codemods/autofix batches per package or directory.