{"record":{"id":"5c0144e6ef6a1ee1","repo":"oxc-project/oxc","slug":"unexpected-redeclaration-of-read-only-global-varia","errorCode":null,"errorMessage":"Unexpected redeclaration of read-only global variable.","messagePattern":"Unexpected redeclaration of read-only global variable\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_implicit_globals.rs","lineNumber":41,"sourceCode":"\nfn global_lexical_binding_diagnostic(kind: &'static str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Unexpected {kind} declaration in the global scope.\"))\n        .with_help(\"Wrap it in a block or in an IIFE.\")\n        .with_label(span)\n}\n\nfn global_variable_leak_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Global variable leak.\")\n        .with_help(\"Declare the variable if it is intended to be local.\")\n        .with_label(span)\n}\n\nfn assignment_to_readonly_global_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected assignment to read-only global variable.\").with_label(span)\n}\n\nfn redeclaration_of_readonly_global_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected redeclaration of read-only global variable.\").with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\nstruct NoImplicitGlobalsConfig {\n    lexical_bindings: bool,\n}\n\n#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]\npub struct NoImplicitGlobals(NoImplicitGlobalsConfig);\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallows declarations in the global scope, global variable leaks, and\n    /// writes or redeclarations of read-only globals.\n    ///\n    /// ### Why is this bad?","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_implicit_globals.rs#L23-L59","documentation":"Reports a var or function declaration at global script scope whose name collides with a read-only global (built-in or configured readonly). Redeclaring built-ins like function Promise() {} overrides the real global for every other script in the runtime, so the rule flags it as 'Unexpected redeclaration of read-only global variable.'","triggerScenarios":"function Promise(executor) {...} as a script-tag polyfill override; var status = 'ready'; or var top = document.getElementById('x'); in a browser script (window properties); var event = ...; shadowing the global handler names.","commonSituations":"Polyfills (Promise, fetch) in script-tag deployments; naming a top-level variable name, length, status, event, or top in browser code; Node examples pasted into browser scripts.","solutions":["Rename the local declaration (appStatus instead of status).","Wrap polyfills in an IIFE and assign to globalThis explicitly when overriding is truly intended.","Give polyfill files a separate lint config where the name is allowed."],"exampleFix":"// before (browser script)\nvar status = 'ready';\n\n// after\nvar appStatus = 'ready';","handlingStrategy":"validation","validationCode":"const redeclare = /^\\s*(?:var|function)\\s+(?:name|status|top|event|length|Promise|fetch)\\b/m.test(source);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid top-level names that collide with window/built-in globals (name, status, top, event, Promise).","Wrap polyfills in IIFEs and assign to globalThis deliberately.","Namespace app globals (myAppStatus) instead of reusing built-in names."],"tags":["oxlint","lint","globals","redeclaration","browser"],"backgroundTag":"global-redeclaration","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"}