robatwilliams / es-compat

Check JavaScript code compatibility with target runtime environments
MIT License
65 stars 13 forks source link

False positives for prototype methods #29

Closed robatwilliams closed 1 year ago

robatwilliams commented 3 years ago

Some features are detected with a chance of false positives - https://github.com/robatwilliams/es-compat/blob/master/packages/eslint-plugin-ecmascript-compat/lib/features/es-versions.md

This will happen all the time if you're using e.g. lodash, or a library that tests for feature presence before using it.

There should be a way of ignoring these, and only report problems that we have full confidence in.

robatwilliams commented 3 years ago

There should be a new optional option detectPrototypeMethods (detect-prototype-methods on the CLI), which when set to false ignores those rules. Document it in the readmes under the packages folder.

The option should be passed into forbiddenFeatures() in compatibility.js, and used to filter out rules. Rule objects in the features folder should have a new optional property isPrototypeMethod: true to identify them.

robatwilliams commented 2 years ago

If you're working around this by parsing the error messages to decide what to ignore, the correct way (i.e. without also ignoring definite real problems) is to look for .prototype. in the message.

robatwilliams commented 2 years ago

https://eslint-plugin-es.mysticatea.dev/#the-aggressive-mode

robatwilliams commented 2 years ago

Solution will probably be:

  1. use the es plugin rules
  2. let the parent project specify aggressive (or not) in its own eslintrc
  3. option on the CLI tool

Need to wait for aggressive mode to be released.

robatwilliams commented 2 years ago

If you're working around this by parsing the error messages to decide what to ignore, the correct way (i.e. without also ignoring definite real problems) is to look for .prototype. in the message.

Recommend that you do each prototype method individually and make sure you have a polyfill in place for each one. See #2

robatwilliams commented 2 years ago

Note this about es plugin aggressive mode:

If using this plugin and TypeScript, this plugin reports prototype methods by default because we can easily know types.

robatwilliams commented 1 year ago

Unblocked by #56

robatwilliams commented 1 year ago

Various usages of no-restricted-syntax to be replaced by specific plugin rules:

2022: https://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-string-prototype-at.html

2021: https://eslint-community.github.io/eslint-plugin-es-x/rules/no-string-prototype-replaceall.html

2020: https://eslint-community.github.io/eslint-plugin-es-x/rules/no-string-prototype-matchall.html

2019: https://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-flat.html https://eslint-community.github.io/eslint-plugin-es-x/rules/no-string-prototype-trimstart-trimend.html https://eslint-community.github.io/eslint-plugin-es-x/rules/no-symbol-prototype-description.html

2018: https://eslint-community.github.io/eslint-plugin-es-x/rules/no-promise-prototype-finally.html

2017: https://eslint-community.github.io/eslint-plugin-es-x/rules/no-string-prototype-padstart-padend.html

2016: https://eslint-community.github.io/eslint-plugin-es-x/rules/no-array-prototype-includes.html

robatwilliams commented 1 year ago

Readme would need updating, including footnotes.

Also features/es-versions.md

robatwilliams commented 1 year ago

Used aggressive mode for es2022 .at() - need to align that with whatever solution is for this issue

robatwilliams commented 1 year ago

These prototype methods have quite distinct names, which developers would normally strive to avoid using for their own methods. So I don't think this is important.

This issue has been open for 2 years and received no comments or thumbs up, which also suggests it's not important.

If you use lodash, add a polyfills entry to silence the false alarms.

Feel free to comment if you read this and want this feature.