no-global-assign
Added in v0.3.4Configuration
Rule Details
Disallows assignments to native objects or read-only global variables. Built-in globals such as Object, Array, String, Number, Math, JSON, undefined, NaN, Infinity, and others should not be reassigned, as doing so can cause unexpected behavior throughout the application.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Globals declared through languageOptions.globals or a /* global */ comment carry their own access level: a readonly name is reported like a built-in, and a writable name may be reassigned — including a built-in whose declaration lifts the default. The environment maps exported as globals from @rslint/core use false for read-only names and true for writable names, so they feed the same access checks directly.
Examples of incorrect code with globals: { BUILD_ID: 'readonly' }:
Examples of correct code with globals: { Object: 'writable' }:
Options
This rule accepts an optional object with an exceptions property, which is an array of global names that should be allowed to be reassigned: