{"record":{"id":"4588c5a09592b097","repo":"oxc-project/oxc","slug":"read-only-global-global-name-should-not-be-mod","errorCode":null,"errorMessage":"Read-only global '{global_name}' should not be modified.","messagePattern":"Read-only global '(.+?)' should not be modified\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/eslint/no_global_assign.rs","lineNumber":15,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_str::CompactStr;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    config::GlobalValue,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_global_assign_diagnostic(global_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Read-only global '{global_name}' should not be modified.\"))\n        .with_help(format!(\"Use a local variable instead of modifying the global '{global_name}'.\"))\n        .with_label(span.label(format!(\"Read-only global '{global_name}' should not be modified.\")))\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct NoGlobalAssign(Box<NoGlobalAssignConfig>);\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoGlobalAssignConfig {\n    /// List of global variable names to exclude from this rule.\n    /// Globals listed here can be assigned to without triggering warnings.\n    exceptions: Vec<CompactStr>,\n}\n\nimpl std::ops::Deref for NoGlobalAssign {\n    type Target = NoGlobalAssignConfig;\n","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_global_assign.rs#L1-L33","documentation":"Diagnostic from oxlint's no-global-assign rule (ESLint port, eslint:recommended). It fires when an assignment writes to a read-only global: a built-in like undefined, NaN, or Infinity, or any variable your lint globals config marks readonly. Such writes throw a TypeError in strict mode or silently no-op in sloppy mode, so the rule stops them statically. The rule config accepts a list of global names to exclude.","triggerScenarios":"undefined = 5; or NaN = NaN + 1;; writing to a global declared readonly in the globals section of .oxlintrc.json; assigning to built-ins like Infinity inside math helpers.","commonSituations":"Legacy browser scripts using undefined as a storable variable; pre-ES5 copied code that 'guarded' undefined; shared lint configs marking environment globals readonly, causing false positives in files that legitimately shadow them.","solutions":["Use a fresh local variable instead of writing to the global.","If the global genuinely should be writable in your environment, declare it writable in the lint globals config.","Add the name to this rule's exceptions list in .oxlintrc.json.","Delete pre-ES5 undefined guards; the property is non-writable in modern engines."],"exampleFix":"// before\nundefined = null; // silent no-op, TypeError in modules\n\n// after\nconst missing = null;","handlingStrategy":"validation","validationCode":"const readonlyWrite = /\\b(?:undefined|NaN|Infinity)\\s*=[^=]/.test(source);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never assign to built-in globals such as undefined, NaN, and Infinity.","Keep the globals section of the lint config accurate per environment (browser/node).","Scope polyfill-style writes to files where the name is marked writable."],"tags":["eslint","oxlint","lint","globals","readonly"],"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-14T11:17:12.474Z"}