question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New Rule: no-override-native-methods | no-assignment-native-props?

See original GitHub issue

Rule details

Prevents overriding native props/methods

Related ECMAScript feature

No

What type of rule is this?

Warns about a potential problem

Example code

Number.isNaN = () => {}; // should be prohibited
Object.entries = () => {}; // should be prohibited
console.log = () => {}; // considered as good, it should be prohibited as well


Number.prototype.isNaN = () => {}; // Number prototype is read only, properties should not be added. (no-extend-native)

Why should this rule be in the core instead of a plugin?

Basically, we need to prevent overriding methods or properties of native classes, and I couldn’t find a solution that makes it possible. Such change might cause pages to work unexpectedly in browsers when there is a native class method get’s overridden and used by libraries that are not related to each other. ESLint can alert if that happens

Participation

  • I am willing to submit a pull request to implement this rule.

Additional comments

Related discussion https://github.com/eslint/eslint/discussions/15110

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
nzakascommented, Oct 5, 2021

@seahindeniz we realize that our policy isn’t what everyone would like, but that’s why ESLint supports plugins. We never want to stand in the way of people having the rules that they want, but we just can’t keep adding new rules to the core forever. With about 300 rules already, it’s a maintenance nightmare.

For more information, please see the blog post where we announced this change: https://eslint.org/blog/2020/05/changes-to-rules-policies

In small projects or projects that don’t have CI flows for ESLint, overriding Number.isNaN can happen intentionally, or some other situations may occur.

It’s clear that you feel strongly about this, and that’s why we have custom rules. You are still free to create a rule that does this, and to use it and even publicize why it’s important to use. This is how ESLint was intended to work: you can configure and extend it to do exactly what you want.

1reaction
aladdin-addcommented, Sep 30, 2021

Per our rules policies, we can only accept new rules if they relate to new ECMAScript features that reached stage 4 in the preceding 12 months, so this proposal doesn’t qualify.

I’m in favor of a new option for no-extend-native.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Able to use NOOVERRIDE=1 in Lightning Experience
We overrided the view button of a Custom Object to a VF page that we made available for Lightning. Based on some criteria,...
Read more >
NOOVERRIDE=1 not working in Lightning Experience
In Salesforce classic, I know I can use nooverride=1, but doesn't seem to work in Lightning. I tried to play with sforce.one.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found