{"record":{"id":"00334eeb62d56e6a","repo":"oxc-project/oxc","slug":"name-is-already-defined-as-a-built-in-global-v","errorCode":null,"errorMessage":"'{name}' is already defined as a built-in global variable.","messagePattern":"'(.+?)' is already defined as a built-in global variable\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_redeclare.rs","lineNumber":24,"sourceCode":"use schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_redeclare_diagnostic(name: &str, decl_span: Span, re_decl_span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"'{name}' is already defined.\"))\n        .with_help(\"Use a different variable name or remove the duplicate declaration.\")\n        .with_labels([\n            decl_span.label(format!(\"'{name}' is already defined.\")),\n            re_decl_span.label(\"It can not be redeclared here.\"),\n        ])\n}\n\nfn no_redeclare_as_builtin_in_diagnostic(name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"'{name}' is already defined as a built-in global variable.\"))\n        .with_help(\"Use a different variable name to avoid shadowing the built-in global.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoRedeclare {\n    /// When set `true`, it flags redeclaring built-in globals (e.g., `let Object = 1;`).\n    builtin_globals: bool,\n}\n\nimpl Default for NoRedeclare {\n    fn default() -> Self {\n        Self { builtin_globals: true }\n    }\n}\n\ndeclare_oxc_lint!(","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_redeclare.rs#L6-L42","documentation":"The built-in-globals variant of `no-redeclare`. It flags any declaration whose name collides with a built-in ECMAScript global (`GLOBALS_BUILTIN`) or with a global enabled in your oxlint `globals` config, e.g. `let Object = 1;`. The check only runs when `builtinGlobals` is true and the file is NOT an ES module, because module top-level bindings shadow nothing.","triggerScenarios":"A script-typed file (no import/export, plain .js script or `<script>` source type) containing `let Object = 1;`, `var event = e;` while `globals: { \"event\": \"readonly\" }` is configured, or TS redeclarations of a builtin-named symbol.","commonSituations":"Teams migrating from ESLint where `builtinGlobals` defaults to false — oxlint defaults it to true, so identical code suddenly fails; adding `globals` entries to .oxlintrc that collide with local variable names in scripts.","solutions":["Rename the local variable so it does not collide with the global name.","Convert the file to an ES module (add import/export or `\"type\": \"module\"`) — the builtin check is skipped for modules.","Set `\"no-redeclare\": [\"error\", { \"builtinGlobals\": false }]` in .oxlintrc to match ESLint's default.","Remove the accidentally enabled name from the `globals` section of .oxlintrc."],"exampleFix":"// before (script file)\nvar Object = { my: 'shim' };\n\n// after\nvar myObjectShim = { my: 'shim' };","handlingStrategy":"validation","validationCode":"// Verify the flag's two preconditions before linting a script file:\n// (1) source is NOT a module, (2) name is a built-in global.\nconst BUILTINS = new Set(Object.getOwnPropertyNames(globalThis));\nconst src = require('node:fs').readFileSync(file, 'utf8');\nconst isModule = /^\\s*(import|export)\\b/m.test(src);\nif (!isModule) {\n  for (const m of src.matchAll(/(?:var|let|const|function)\\s+([A-Za-z_$][\\w$]*)/g)) {\n    if (BUILTINS.has(m[1]) || /event|self|name|status|top|length/.test(m[1]))\n      console.warn(`possible builtin shadow: ${m[1]} at ${m.index}`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set `\"builtinGlobals\": false` in .oxlintrc when migrating an ESLint config so behavior matches.","Keep scripts as ES modules (`\"type\": \"module\"`) — the builtin-globals half of the rule is skipped for modules.","Avoid naming locals after DOM/JS globals (`event`, `name`, `self`, `Object`) even when the linter allows it."],"tags":["lint","eslint","no-redeclare","globals","shadowing","configuration"],"backgroundTag":"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"}