no-shadow
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"no-shadow": "error",
},
},
];Disallow variable declarations from shadowing variables declared in the outer scope
const a = 3;
function b() {
const a = 10;
}
const c = function () {
const a = 10;
}
function d(a) {
a = 10;
}
d(a);
if (true) {
const a = 5;
}
const f = wrap(function f() {});
const C = wrap(class C {});const a = 3;
function b(c) {
const d = 10;
if (c) {
const e = 20;
}
}
/*
* Function and class names are allowed to shadow a variable
* if the function/class expression is assigned to the variable
* as its initializer or default value.
*/
const f = function f() {};
const g = foo ? (bar || function g() {}) : baz;
const { h = function h() {} } = obj;
function qux(i = function i() {}) {}
const C = class C {};Examples from the ESLint documentation.
no-shadow
eslint
export default [
{
rules: {
"no-shadow": "error",
},
},
];no-shadow
eslint plugin · suspicious
{
"rules": {
"no-shadow": "error"
}
}suspicious/noShadow
suspicious · since 2.0.0
{
"linter": {
"rules": {
"suspicious": {
"noShadow": "error"
}
}
}
}Disallow variable declarations from shadowing variables declared in the outer scope
Disallow nested ternary expressions
Enforce a maximum number of classes per file
Enforce default parameters to be last
Require default cases in switch statements