{"record":{"id":"a914bec2310f2ab2","repo":"oxc-project/oxc","slug":"unexpected-use-of-global-name","errorCode":null,"errorMessage":"Unexpected use of '{global_name}'.","messagePattern":"Unexpected use of '(.+?)'\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_restricted_globals.rs","lineNumber":28,"sourceCode":"use oxc_str::CompactStr;\nuse rustc_hash::FxHashMap;\nuse schemars::{\n    JsonSchema, SchemaGenerator,\n    schema::{ArrayValidation, Schema, SchemaObject},\n};\nuse serde::de::Error;\nuse serde_json::Value;\n\nuse crate::{AstNode, ast_util::iter_outer_expressions, context::LintContext, rule::Rule};\n\nfn no_restricted_globals(global_name: &str, suffix: &str, span: Span) -> OxcDiagnostic {\n    let warn_text = if suffix.is_empty() {\n        format!(\"Unexpected use of '{global_name}'.\")\n    } else {\n        format!(\"Unexpected use of '{global_name}'. {suffix}\")\n    };\n\n    OxcDiagnostic::warn(warn_text)\n        .with_help(\"Use a local variable or function parameter instead of the restricted global.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Clone, Default)]\npub struct NoRestrictedGlobals(Box<NoRestrictedGlobalsConfig>);\n\nimpl Deref for NoRestrictedGlobals {\n    type Target = NoRestrictedGlobalsConfig;\n\n    fn deref(&self) -> &Self::Target {\n        &self.0\n    }\n}\n\n#[derive(Debug, Clone)]\npub struct NoRestrictedGlobalsConfig {\n    /// Objects in the format","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_restricted_globals.rs#L10-L46","documentation":"oxlint's port of ESLint `no-restricted-globals`. It fires on any free-variable reference to a global listed in the rule config, e.g. the legacy `event` object. Config entries can be plain strings or `{ name, message }` objects — a message is appended to the diagnostic text as a suffix.","triggerScenarios":"`\"no-restricted-globals\": [\"error\", \"event\", \"isFinite\"]` in .oxlintrc, then code referencing `event.target` or `isFinite(x)` as a bare identifier (the rule checks references found via `iter_outer_expressions`, not string literals or member roots).","commonSituations":"Banning browser-only globals (`event`, `window`) in SSR/isomorphic code; banning `isFinite`/`parseInt` in favor of `Number.isFinite`/`parseInt` with radix; teams migrating from ESLint keeping the same config.","solutions":["Get the value explicitly, e.g. accept an `event` parameter from `addEventListener` instead of the implicit global.","Replace the disallowed global with the modern alternative (`Number.isFinite`, `globalThis`).","Add a `{ name, message }` entry so the diagnostic explains the required replacement.","Remove the name from the rule config if the restriction no longer applies."],"exampleFix":"// before\nbutton.addEventListener('click', () => {\n  console.log(event.target);\n});\n\n// after\nbutton.addEventListener('click', (event) => {\n  console.log(event.target);\n});","handlingStrategy":"validation","validationCode":"// Detect bare references to restricted globals before lint runs\nconst RESTRICTED = new Set(['event', 'isFinite', 'parseFloat', 'setTimeout']);\nfunction usesRestrictedGlobals(src) {\n  return [...src.matchAll(/(?<![.\\w$])([A-Za-z_$][\\w$]*)/g)]\n    .map(m => m[1])\n    .filter(name => RESTRICTED.has(name));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always take `event`/`window` as explicit parameters (e.g. `(event) => ...` in addEventListener callbacks).","Use `Number.isFinite`/`Number.parseFloat` instead of the global coercing versions.","Configure `{ name, message }` entries so each hit tells the author the replacement."],"tags":["lint","eslint","no-restricted-globals","globals","configuration"],"backgroundTag":"restricted-global-usage","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"}