Skip to main content

no-use-extend-native

Disallow usage of non-native members on built-in JavaScript objects.

Targeted pattern scope

This rule is intentionally conservative and focuses on obvious built-in object shapes such as:

  • String/number/boolean/regexp literals.
  • Array/object literals.
  • new expressions for built-ins.
  • String.prototype.<member> / Array.prototype.<member> style accesses.

It does not attempt full-flow inference for arbitrary identifiers.

What this rule reports

This rule helps prevent implicit reliance on monkey-patched native prototypes (for example from legacy libraries that add methods like String.prototype.green).

This rule reports member usage on obvious built-in values when the accessed member is not part of the native API.

Why this rule exists

Relying on extended native objects can make code unpredictable across runtimes, bundling targets, and dependency versions.

❌ Incorrect

const value = "unicorn".green;
const value = [].customFunction();
const value = String.prototype.shortHash();

✅ Correct

const value = "unicorn".toUpperCase();
const value = [].map((entry) => entry);
const value = String.prototype.toLowerCase.call("ABC");

Behavior and migration notes

This rule has no options.

Relationship to ESLint no-extend-native

  • ESLint core no-extend-native prevents adding properties to native prototypes.
  • This rule prevents consuming non-native members when they appear in code.

Using both rules together gives better protection:

  1. Prevent introducing prototype extension.
  2. Prevent relying on prototype extension from third-party code.

Original plugin source: eslint-plugin-no-use-extend-native.

ESLint flat config example

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-use-extend-native": "error",
},
},
];

When not to use it

  • If your project intentionally and explicitly relies on controlled prototype extension.
  • If your runtime environment guarantees specific prototype patches and that dependency is accepted in your architecture.

Further reading