oxc-project/oxc · warning
Global variable leak.
Error message
Global variable leak.
What it means
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.
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.
Example fix
// before
function start() {
isLoading = true;
}
// after
let isLoading = false;
function start() {
isLoading = true;
} Defensive patterns
Strategy: validation
Validate before calling
npx oxlint -A all -D no-undef src/ // no-undef flags implicit-global writes
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unexpected declaration in the global scope.
- ' ' is not defined.
- Import the following Jest functions from `@jest/globals
- ' ' is already a global variable.
- Read-only global ' ' should not be modified.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/d5c2ffa5ed82ebfd.
Report an issue: GitHub.
Appendix: source
Thrown at crates/oxc_linter/src/rules/eslint/no_implicit_globals.rs:31
rule::{DefaultRuleConfig, Rule},
};
fn global_non_lexical_binding_diagnostic(kind: &'static str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Unexpected {kind} declaration in the global scope."))
.with_help(
"Wrap it in an IIFE for a local variable, or assign it as a global property for a global variable.",
)
.with_label(span)
}
fn global_lexical_binding_diagnostic(kind: &'static str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Unexpected {kind} declaration in the global scope."))
.with_help("Wrap it in a block or in an IIFE.")
.with_label(span)
}
fn global_variable_leak_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Global variable leak.")
.with_help("Declare the variable if it is intended to be local.")
.with_label(span)
}
fn assignment_to_readonly_global_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected assignment to read-only global variable.").with_label(span)
}
fn redeclaration_of_readonly_global_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unexpected redeclaration of read-only global variable.").with_label(span)
}
#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
struct NoImplicitGlobalsConfig {
lexical_bindings: bool,
}
View on GitHub (pinned to e1e7af627c)