eslint-plugin-unicorn icon indicating copy to clipboard operation
eslint-plugin-unicorn copied to clipboard

Add `no-unnecessary-polyfills` rule

Open Mesteery opened this issue 3 years ago • 12 comments

Fixes: https://github.com/sindresorhus/eslint-plugin-unicorn/issues/36


IssueHunt Summary

Referenced issues

This pull request has been submitted to:


Mesteery avatar Feb 05 '22 23:02 Mesteery

For core-js@3 / core-js-pure, use core-js-compat - @babel/compat-data is not the proper data source for them.

zloirock avatar Feb 06 '22 03:02 zloirock

Is this what you suggested? @zloirock

Mesteery avatar Feb 12 '22 17:02 Mesteery

@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.

zloirock avatar Feb 13 '22 21:02 zloirock

Sorry, but I didn't quite understand that.

Mesteery avatar Feb 15 '22 16:02 Mesteery

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.

zloirock avatar Feb 15 '22 17:02 zloirock

Like this https://github.com/sindresorhus/eslint-plugin-unicorn/pull/1717/commits/707f4f2b3a5c2a24ff651e267039e1c6840dfc8f?

Mesteery avatar Feb 15 '22 18:02 Mesteery

Yes, something like that.

zloirock avatar Feb 15 '22 18:02 zloirock

PTAL @fisker

Mesteery avatar Mar 06 '22 10:03 Mesteery

Sorry for the delay, I'll review ASAP.

fisker avatar Jul 19 '22 01:07 fisker

The tests are failing.

fisker avatar Sep 04 '22 17:09 fisker

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.

Mesteery avatar Sep 05 '22 18:09 Mesteery

Thanks you! Is it ready or i missed some changes?

Mesteery avatar Sep 07 '22 16:09 Mesteery

@Mesteery Bump

sindresorhus avatar Feb 01 '23 15:02 sindresorhus

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'}

Mesteery avatar Feb 05 '23 19:02 Mesteery

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

fisker avatar Feb 06 '23 00:02 fisker

If I understand you want node.engines to be core-js targets?

Mesteery avatar Feb 28 '23 16:02 Mesteery

Bump

sindresorhus avatar Jun 20 '23 11:06 sindresorhus

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.

fisker avatar Jun 20 '23 11:06 fisker

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.

Mesteery avatar Jul 01 '23 15:07 Mesteery

CI is failing

sindresorhus avatar Oct 29 '23 19:10 sindresorhus