{"record":{"id":"d5c2ffa5ed82ebfd","repo":"oxc-project/oxc","slug":"global-variable-leak","errorCode":null,"errorMessage":"Global variable leak.","messagePattern":"Global variable leak\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_implicit_globals.rs","lineNumber":31,"sourceCode":"    rule::{DefaultRuleConfig, Rule},\n};\n\nfn global_non_lexical_binding_diagnostic(kind: &'static str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Unexpected {kind} declaration in the global scope.\"))\n        .with_help(\n            \"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","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_implicit_globals.rs#L13-L49","documentation":"The leak diagnostic of oxlint's no-implicit-globals rule. An assignment to a name that is never declared anywhere creates an implicit global at runtime (and throws a ReferenceError under 'use strict' or in modules). The rule flags the assignment with 'Global variable leak.' and suggests declaring the variable if it is intended to be local.","triggerScenarios":"isLoading = true; inside a function where no let isLoading exists anywhere; typo'd targets like resutl = compute(); a declaration removed during refactor while assignments remain.","commonSituations":"Sloppy-mode legacy code; typos in assignment targets; state declared in one branch and assumed to hoist; merges that drop a declaration but keep its writes.","solutions":["Add a declaration (let isLoading = false) in the intended scope.","Fix the typo in the identifier name.","If the value really is global, assign it explicitly on globalThis/window.","Enable strict mode or ES modules so the runtime also fails fast."],"exampleFix":"// before\nfunction start() {\n  isLoading = true;\n}\n\n// after\nlet isLoading = false;\nfunction start() {\n  isLoading = true;\n}","handlingStrategy":"validation","validationCode":"npx oxlint -A all -D no-undef src/  // no-undef flags implicit-global writes","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare every variable you assign (let/const/var) in the intended scope.","Enable strict mode or ES modules so implicit globals throw at runtime.","Run no-undef in CI to catch typo'd targets before they leak."],"tags":["oxlint","lint","globals","scope","typos"],"backgroundTag":"implicit-global-variable","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}