Linter · Rules
no-shadow-restricted-names
Disallow variables named undefined, NaN, Infinity, eval, arguments or globalThis
undefined, NaN and Infinity look like keywords, but they're ordinary globals, so a variable or a parameter can take their name. After const undefined = "none", every value === undefined in that scope compares with "none".
The rule reports variables, parameters, functions, classes and imports with one of these names.
This rule is on by default.
Configure
On by default as a warning. To turn it off:
bunfig.toml
[lint.rules]
"no-shadow-restricted-names" = "off" # or "error"
Every option, set to its default:
bunfig.toml
[lint.rules]
"no-shadow-restricted-names" = ["warn", {
reportGlobalThis = true,
}]
Examples
Reported:
const undefined = "none";
function toNumber(text, NaN) {
return text === "" ? NaN : Number(text);
}
Not reported:
const missing = "none";
function toNumber(text, fallback) {
return text === "" ? fallback : Number(text);
}
A variable named undefined that never gets a value is allowed, because it's the same as the global:
var undefined;
Options
| Option | Default | What it does |
|---|---|---|
reportGlobalThis | true | Also report globalThis. |
If your project has an ESLint config and ESLint 9 or older installed, the default is false, as it is there.
const globalThis = window;
const globalThis = window;