{"record":{"id":"7330b6d08ef44e0d","repo":"oxc-project/oxc","slug":"name-is-already-a-global-variable","errorCode":null,"errorMessage":"'{name}' is already a global variable.","messagePattern":"'(.+?)' is already a global variable\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_shadow/mod.rs","lineNumber":56,"sourceCode":"            .with_help(format!(\n                \"Consider renaming '{name}' to avoid shadowing the variable from the outer scope.\"\n            ))\n            .with_labels([\n                span.label(format!(\"'{name}' is declared here\")),\n                shadowed_span.label(\"shadowed declaration is here\"),\n            ]);\n\n    if is_enum_member {\n        diagnostic.with_note(format!(\n            \"Enum members are added to the enum scope, so references to '{name}' in enum member initializers resolve to this member instead of the declaration in the upper scope.\"\n        ))\n    } else {\n        diagnostic\n    }\n}\n\npub fn no_shadow_global_diagnostic(span: Span, name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"'{name}' is already a global variable.\"))\n        .with_help(format!(\"Consider renaming '{name}' to avoid shadowing the global variable.\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoShadow(Box<NoShadowConfig>);\n\nimpl std::ops::Deref for NoShadow {\n    type Target = NoShadowConfig;\n\n    fn deref(&self) -> &Self::Target {\n        &self.0\n    }\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_shadow/mod.rs#L38-L74","documentation":"oxlint's `no-shadow` rule emits this diagnostic (from `no_shadow_global_diagnostic`) when a local binding — var/let/const, function or class declaration, parameter, or catch binding — reuses the name of a JavaScript builtin global such as `name`, `length`, `status`, or `Promise`. The lookup uses the `javascript_globals::GLOBALS` table, so the exact set depends on the configured environment (browser, node, etc.). It is a static-analysis warning: the local binding hides the global inside that scope, so code that appears to reference the global actually references the local.","triggerScenarios":"Declaring any binding whose name matches an entry in the GLOBALS table for your env: `const name = 'x'` inside a function, `class Promise {}`, a function parameter named `event`, a catch parameter named `length`. The diagnostic fires once per shadowing symbol found while iterating `scoping.symbol_ids()` in the rule's `run_once`.","commonSituations":"Enabling stricter no-shadow settings (ESLint's `builtinGlobals: true` behavior); browser projects accidentally shadowing `name`, `length`, `status`, `self`, or `event`; porting an ESLint config to oxlint where globals come from the `globals` configuration instead of `env`, suddenly surfacing dozens of hits.","solutions":["Rename the local binding to something specific (e.g. `name` -> `userName`).","If the shadowing is intentional, suppress it inline with `// oxlint-disable-next-line eslint/no-shadow`.","Review the rule's config (HoistOption / NoShadowConfig) to stop reporting hoisted functions before use.","Adjust the `globals` configuration in .oxlintrc.json so env globals you never intend to shadow are the only ones checked."],"exampleFix":"// before\nfunction greet() {\n  const name = 'Ada'; // shadows the browser global `name`\n  return name;\n}\n\n// after\nfunction greet() {\n  const userName = 'Ada';\n  return userName;\n}","handlingStrategy":"validation","validationCode":"# CI gate before merge\nnpx oxlint -c .oxlintrc.json src/ # .oxlintrc.json: { \"rules\": { \"eslint/no-shadow\": \"warn\" } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid naming locals after well-known globals (name, length, status, event, self, Promise).","Keep the `globals` config aligned with the actual runtime environment so shadow checks are meaningful.","Review shadow warnings during code review — most are one-line renames."],"tags":["eslint","oxlint","no-shadow","scope","globals","static-analysis"],"backgroundTag":"variable-shadowing","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}