Linter · Rules
no-global-assign
Disallow assigning to built-in and other read-only global variables
Assigning to a global such as Promise or window replaces it for all the code that runs afterwards, including libraries. More often it's an accident. A const or let is missing, and the name you picked is already a browser global.
This rule is on by default.
Configure
On by default as a warning. To turn it off:
bunfig.toml
[lint.rules]
"no-global-assign" = "off" # or "error"
Every option, set to its default:
bunfig.toml
[lint.rules]
"no-global-assign" = ["warn", {
exceptions = [], # list of strings
}]
Examples
Reported:
Promise = loadPromiseLibrary();
window = createFakeWindow();
status = "ready";
Not reported:
const Promise = loadPromiseLibrary();
let status = "ready";
status = "done";
A global that's declared as writable can be assigned:
/* global analytics:writable */
analytics = createAnalytics();
/* global analytics:readonly */
analytics = createAnalytics();
Options
| Option | Default | What it does |
|---|---|---|
exceptions | [] | Names of read-only globals that can be assigned. |
Promise = loadPromiseLibrary();