{"record":{"id":"29739dd7c106b19b","repo":"oxc-project/oxc","slug":"prefer-globalthis-over-environment-specific-glob","errorCode":null,"errorMessage":"Prefer `globalThis` over environment-specific global aliases like `window`, `self`, and `global`.","messagePattern":"Prefer `globalThis` over environment-specific global aliases like `window`, `self`, and `global`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_global_this.rs","lineNumber":10,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::operator::UnaryOperator;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn prefer_global_this_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer `globalThis` over environment-specific global aliases like `window`, `self`, and `global`.\")\n        .with_help(\"Replace the alias with `globalThis`.\")\n        .with_note(\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferGlobalThis;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Enforces the use of [`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis) instead of\n    /// environment‑specific global object aliases (`window`, `self`, or `global`).\n    ///\n    /// Using the standard `globalThis` makes your code portable across browsers, Web Workers, Node.js,\n    /// and future JavaScript runtimes.\n    ///\n    /// ### Why is this bad?","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_global_this.rs#L1-L28","documentation":"Diagnostic from the unicorn/prefer-global-this lint rule. It fires when code references an environment-specific global alias (`window`, `self`, `global`, or `globalThis` variants under unary checks) instead of the standard `globalThis`, making the code non-portable across browsers, workers, and Node. The flagged input is the identifier reference to the alias. It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_global_this.rs:10 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace `window`/`self`/`global` with `globalThis`","Use `typeof globalThis` checks instead of alias-specific environment detection","Apply the rule's auto-fix"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}