{"record":{"id":"460ad6bcfdbc2835","repo":"oxc-project/oxc","slug":"shadowing-of-global-properties-such-as-undefined","errorCode":null,"errorMessage":"Shadowing of global properties such as `undefined` is not allowed.","messagePattern":"Shadowing of global properties such as `undefined` is not allowed\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/eslint/no_shadow_restricted_names.rs","lineNumber":16,"sourceCode":"use crate::{\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\nuse oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\nuse serde_json::Value;\n\nconst PRE_DEFINE_VAR: [&str; 5] = [\"Infinity\", \"NaN\", \"arguments\", \"eval\", \"undefined\"];\n\nfn no_shadow_restricted_names_diagnostic(shadowed_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Shadowing of global properties such as `undefined` is not allowed.\")\n        .with_help(format!(\"Rename '{shadowed_name}' to avoid shadowing the global property.\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct NoShadowRestrictedNames(Box<NoShadowRestrictedNamesConfig>);\n\n#[derive(Debug, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoShadowRestrictedNamesConfig {\n    /// If true, also report shadowing of `globalThis`.\n    report_global_this: bool,\n}\n\nimpl Default for NoShadowRestrictedNamesConfig {\n    fn default() -> Self {\n        Self { report_global_this: true }\n    }","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_shadow_restricted_names.rs#L1-L34","documentation":"`no-shadow-restricted-names` reports any binding that shadows one of the five restricted names in `PRE_DEFINE_VAR`: `Infinity`, `NaN`, `arguments`, `eval`, `undefined`; with `report_global_this: true` it also reports shadowing `globalThis`. Shadowing `eval` or `arguments` is a hard SyntaxError in strict mode, and shadowing `undefined`/`NaN`/`Infinity` makes reads inside that scope silently return the local value instead of the global. The rule flags declarations, parameters, and catch bindings with these names.","triggerScenarios":"Writing `var undefined = 5;`, `function f(eval) {}`, `let NaN = compute();`, `catch (arguments) {}`, or (with `reportGlobalThis: true`) `const globalThis = window;`.","commonSituations":"Copy-pasted legacy code (pre-ES5) declaring `var undefined`; minified or machine-generated code reusing short global names; enabling `reportGlobalThis` after upgrading oxlint and hitting polyfill shims that alias `globalThis`.","solutions":["Rename the shadowing binding to anything else — there is no valid reason to keep these names.","For `globalThis` specifically, either rename the alias or disable `reportGlobalThis` in the rule config if the shim is intentional.","Run `oxlint --fix` is not applicable here; rename manually, then re-run the linter to confirm zero hits."],"exampleFix":"// before\nfunction f() {\n  var undefined = false;\n  return undefined; // always false, not the global undefined\n}\n\n// after\nfunction f() {\n  var isReady = false;\n  return isReady;\n}","handlingStrategy":"validation","validationCode":"# quick textual pre-check for restricted-name shadowing\nrg -n '\\b(var|let|const|function|class)\\s+(undefined|NaN|Infinity|eval)\\b|catch\\s*\\(\\s*(undefined|NaN|Infinity|eval)\\s*\\)' src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never declare bindings named undefined, NaN, Infinity, eval, or arguments.","Strict-mode code fails to parse on eval/arguments bindings — enable 'use strict' to catch early.","Lint generated code too; restrict these names in code generators' identifier pools."],"tags":["eslint","oxlint","no-shadow-restricted-names","restricted-globals","scope","strict-mode"],"backgroundTag":"restricted-global-shadowing","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}