robatwilliams / es-compat

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

ES2016 method 'Array.prototype.includes' is forbidden _eslint(ecmascript-compat/compat)_ #47

Closed dossy closed 2 years ago

dossy commented 2 years ago

I'm using plugin:ecmascript-compat/recommended and my browserslist is set to last 5 Chrome versions which absolutely supports ES2016 and Array.prototype.includes, yet ecma-compat/compat says this is forbidden?

In mdn/browser-compat-data, it lists Array.prototype.includes as being added in Chrome 47, which is certainly older than the last 5 Chrome versions.

If I'm reading things correctly, this is actually being picked up by eslint's no-restricted-syntax rule, as configured by eslint-plugin-ecmascript-compat's es2016.js.

Am I misunderstanding what this eslint plugin is supposed to do? Or is this a bug somewhere, because Array.prototype.inclues is definitely available in modern Chrome.

I'm silencing the error with eslint-disable-next-line ecmascript-compat/compat for now, but is less than ideal.

dossy commented 2 years ago

Is this another instance of #30 ?

robatwilliams commented 2 years ago

Yes, I expect so - because chrome 100 is now probably in "last 5 versions"

dossy commented 2 years ago

Interesting, now when I run eslint it seems to work as expected? I blew away my node_modules and did a fresh yarn install and it now magically works? I'm confused.

$ echo 'Array.prototype.includes' > test.js

$ BROWSERSLIST="last 5 Chrome versions" eslint test.js
es-compat: checking compatibility for targets { chrome: '95' }

$ BROWSERSLIST="Chrome < 47" eslint test.js
es-compat: checking compatibility for targets { chrome: '10' }

/Volumes/Alt-ExternalHD/Users/dossy/Work/Upwork/dev/better-upwork/test.js
  1:1  error  ES2016 method 'Array.prototype.includes' is forbidden  ecmascript-compat/compat

✖ 1 problem (1 error, 0 warnings)

But, then I'm guessing this is what issue #30 is fixing:

$ BROWSERSLIST="Safari >= 15" eslint test.js
es-compat: checking compatibility for targets { safari: '15' }

/Volumes/Alt-ExternalHD/Users/dossy/Work/Upwork/dev/better-upwork/test.js
  1:1  error  ES2016 method 'Array.prototype.includes' is forbidden  ecmascript-compat/compat

✖ 1 problem (1 error, 0 warnings)

BROWSERSLIST="Safari >= 9" eslint test.js
es-compat: checking compatibility for targets { safari: '10' }

/Volumes/Alt-ExternalHD/Users/dossy/Work/Upwork/dev/better-upwork/test.js
  1:1  error  ES2016 method 'Array.prototype.includes' is forbidden  ecmascript-compat/compat

✖ 1 problem (1 error, 0 warnings)

I'll close this issue as I cannot reproduce the original issue specifically with Chrome, but I can definitely reproduce issue #30, and @lamansky's fix in #46 fixes the Safari cases for me, at least.

robatwilliams commented 1 year ago

Released https://github.com/robatwilliams/es-compat/releases/tag/v3.0.0

including fix for #30

FYI @dossy