no-extend-native
Configuration
Disallows directly modifying the prototype of native built-in objects (Object,
Array, Function, String, Number, Boolean, Symbol, Map, Set,
Promise, Error, RegExp, Date, BigInt, WeakRef,
FinalizationRegistry, etc.).
Rule Details
Extending native prototypes is generally regarded as a bad practice because it breaks assumptions other code makes about builtins, can collide with future language additions, and is invisible to the rest of the program until it is triggered at runtime.
The rule reports two extension patterns:
- Direct assignment, including compound and logical assignments:
Builtin.prototype.foo = ...,Builtin.prototype.foo ??= .... Object.defineProperty(Builtin.prototype, ...)andObject.defineProperties(Builtin.prototype, ...).
References to the builtin that are shadowed by a local declaration in scope
(e.g. function foo() { var Object = function () {}; Object.prototype.p = 0 })
are not reported.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
With { "exceptions": ["Object"] }, the following becomes valid: