{"record":{"id":"f2c68da9bec2a69b","repo":"oxc-project/oxc","slug":"unexpected-assignment-to-read-only-global-variable","errorCode":null,"errorMessage":"Unexpected assignment to read-only global variable.","messagePattern":"Unexpected assignment to read-only global variable\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_implicit_globals.rs","lineNumber":37,"sourceCode":"            \"Wrap it in an IIFE for a local variable, or assign it as a global property for a global variable.\",\n        )\n        .with_label(span)\n}\n\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    ///","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_implicit_globals.rs#L19-L55","documentation":"The read-only variant inside oxlint's no-implicit-globals rule: writing to a global that the lint config (or well-known built-ins) marks read-only, such as undefined, NaN, Infinity, or environment globals declared readonly. In strict mode such writes throw a TypeError at runtime; in sloppy mode they silently no-op, so the rule reports them statically.","triggerScenarios":"undefined = fallback;; assigning to a global listed as readonly in the globals section of .oxlintrc.json; polyfill code overwriting readonly names in the same lint pass as application code.","commonSituations":"Old defensive-undefined assignments; shared configs marking environment globals readonly; polyfill files linted with the app's strict settings.","solutions":["Use a new local variable instead of writing to the global.","Mark the global writable in the globals config if assignment is legitimate (e.g. dedicated polyfill files).","Delete pre-ES5 undefined guards."],"exampleFix":"// before\nundefined = 'fallback';\n\n// after\nconst fallback = 'fallback';","handlingStrategy":"validation","validationCode":"const readonlyWrite = /\\b(?:undefined|NaN|Infinity)\\s*=[^=]/.test(source);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never write to globals your config marks readonly.","Keep polyfill files under a separate lint config with the names writable.","Delete legacy undefined-assignment guards on sight."],"tags":["oxlint","lint","globals","readonly","assignment"],"backgroundTag":"readonly-global-assignment","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"}