eslint-plugin-unicorn
eslint-plugin-unicorn copied to clipboard
Add `no-unnecessary-polyfills` rule
Fixes: https://github.com/sindresorhus/eslint-plugin-unicorn/issues/36
IssueHunt Summary
Referenced issues
This pull request has been submitted to:
For core-js@3 / core-js-pure, use core-js-compat - @babel/compat-data is not the proper data source for them.
Is this what you suggested? @zloirock
@Mesteery for core-js - yes, but not for the rest polyfills. I meant that you could use entries for the rest polyfills too. For example, you can get the list of features like
Object.keys(coreJsEntries).flatMap(it => (it.startsWith('core-js/actual/') && !/\/(virtual|instance)\//.test(it)) ? it.slice(15) : [])
and operate with them like with core-js entries.
Sorry, but I didn't quite understand that.
core-js modules do not directly correspond to language features. Entry points - correspond. Many language features depend on some modules, like with Set example above. A module is an abstract part of a language feature polyfill.
For example, you have an import of string-at-polyfill. With your regex patterns, you can understand that it's an at method of String. However, core-js module for this feature is es.string.at-alternative - you can't directly rely on it. However, since you know that it's an at method of String, you can rely on core-js/actual/string/at data and you will see that this feature depends on es.string.at-alternative module - and check compact data for this module. If it depends on some modules - you can check all of them, like now it's done in the core-js case.
Like this https://github.com/sindresorhus/eslint-plugin-unicorn/pull/1717/commits/707f4f2b3a5c2a24ff651e267039e1c6840dfc8f?
Yes, something like that.
PTAL @fisker
Sorry for the delay, I'll review ASAP.
The tests are failing.
Fixed. The errors is due to STATIC_REQUIRE_SOURCE_SELECTOR (maybe i misused it, but it worked correctly with STATIC_REQUIRE_SELECTOR), and the Object.assign (. instead of #, in tests), there is no way to know if it is a static method or not... except hardcoding static methods.
Thanks you! Is it ready or i missed some changes?
@Mesteery Bump
I'm sorry for all the delay, I was really busy. (btw, I don't know how to fix the markdown lint error)
I have a doubt about one thing, I'm not sure if corejs({targets}) supports SemVer syntax with targets = {node:'semver'}
I'm not sure if corejs({targets}) supports SemVer syntax with targets = {node:'semver'}
https://github.com/sindresorhus/eslint-plugin-unicorn/pull/1717#discussion_r961621787
If I understand you want node.engines to be core-js targets?
Bump
I mean I don't know if core-js accept engines if not, translate to targets, other user input targets pass directly to core-js.
I apologize again for the delay. I've slightly refactored the code, and I passed engines directly to corejs targets if browserlist is not defined (and I've removed useBrowserlistFieldByDefault, as I think it would make more sense to always have engines as a last resort). However, I'm not sure that corejs correctly supports the semver syntax that can be used in engines.
CI is failing