noGlobalAssign (since v1.5.0)
Diagnostic Category: lint/nursery/noGlobalAssign
Source: no-global-assign
Disallow assignments to native objects and read-only global variables.
_JavaScript environments contain numerous built-in global variables, such as window
in browsers and process
in _Node.js.
Assigning values to these global variables can be problematic as it can override essential functionality.
Examples
Section titled ExamplesInvalid
Section titled InvalidObject = null;
nursery/noGlobalAssign.js:1:1 lint/nursery/noGlobalAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ A global variable should not be reassigned.
> 1 │ Object = null;
│ ^^^^^^^
2 │
ℹ Assigning to a global variable can override essential functionality.
window = {};
nursery/noGlobalAssign.js:1:1 lint/nursery/noGlobalAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ A global variable should not be reassigned.
> 1 │ window = {};
│ ^^^^^^^
2 │
ℹ Assigning to a global variable can override essential functionality.
undefined = true;
nursery/noGlobalAssign.js:1:1 lint/nursery/noGlobalAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ A global variable should not be reassigned.
> 1 │ undefined = true;
│ ^^^^^^^^^^
2 │
ℹ Assigning to a global variable can override essential functionality.
Valid
Section titled Valida = 0;
let window;window = {};