robatwilliams / es-compat

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

Allow specifying provided polyfills #2

Closed robatwilliams closed 1 year ago

robatwilliams commented 4 years ago

Whitelist particular non-syntax features as "polyfill provided", so they aren't reported as problems.

The list would be specified as an option to the rule:

{
  "rules": {
    "ecmascript-compat/compat": [
      "error",
      {
        "polyfills": [
          "Array.prototype.flat"
        ]
      }
    ]
  }
}
dobesv commented 3 years ago

Indeed I seem to be in need of this:


/home/ubuntu/app/dist/web/10.js
   24:260  error  ES2017 'Object.getOwnPropertyDescriptors' method is forbidden  ecmascript-compat/compat
   24:328  error  ES2017 'Object.getOwnPropertyDescriptors' method is forbidden  ecmascript-compat/compat
  193:260  error  ES2017 'Object.getOwnPropertyDescriptors' method is forbidden  ecmascript-compat/compat
  193:328  error  ES2017 'Object.getOwnPropertyDescriptors' method is forbidden  ecmascript-compat/compat
robatwilliams commented 2 years ago

This would still be doable with https://eslint-plugin-es.mysticatea.dev/#the-aggressive-mode - we'd just not enable the rules at all.

robatwilliams commented 2 years ago

Example of someone working around the absence of this feature: https://github.com/moodlehq/moodleapp/blob/393790412d1ab3fd4a1cc951427ba071c9af2195/.github/workflows/testing.yml#L59

robatwilliams commented 2 years ago

Similar problem is guarded usage (feature detection), e.g. in libraries - e.g. globalThis, Object.getOwnPropertyDescriptors

lukeapage commented 2 years ago

We plan to implement this too- will you have time to review and merge it? and are still happy with your solution?

robatwilliams commented 2 years ago

Yes at some point, I'm a bit otherwise occupied over the summer.

And yes the options structure I drafted in the issue description still looks ok, if it still makes sense once someone digs into implementing it.

sobstel commented 1 year ago

@robatwilliams @lukeapage Could you please have a look if this approach looks ok to you: https://github.com/robatwilliams/es-compat/pull/50?

I've also considered wrapping rules, so we could exclude them before even using (might a bit more efficient), but implementation would be much more complex than doing simple message text comparison.

robatwilliams commented 1 year ago

Hi, and thanks. Started discussion on the PR about this.

robatwilliams commented 1 year ago

This is now released in v2.2.0 thanks to the work of @sobstel .

FYI @jedlikowski (liked), @dobesv (commented), @NoelDeMartin (workaround in moodleapp), @zloirock (mentioned interest via #51)