The prototype of a built-in such as Array gains or changes a member for the whole program
What it finds
Array.prototype.last = function () { ... }: adding to or changing the prototype of a built-in changes every array, string or object in the program, including those of libraries that do not expect it. Names can clash with methods a later version of the language adds, and for-in loops start to see the new property.
Reported are assignments to a member of X.prototype and Object.defineProperty or Object.defineProperties on X.prototype, where X is a global built-in such as Array, Object, String or Promise. Polyfills do this on purpose, which is why the rule is recommended rather than on by default.
From the rule's source, builtin_prototype_change.rs.
Array.prototype.last = function () {tx0 reports: this changes Array.prototype for all code in the program return this[this.length - 1];};Object.defineProperty(String.prototype, "shout", { value: () => "!" });tx0 reports: this changes String.prototypeclass Mine {}Mine.prototype.extra = 1; Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:builtin-prototype-change" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:builtin-prototype-change] reason="..."tx0 explain tx0/ts:builtin-prototype-change shows the same in the terminal. Found a false positive? Report it.