amilajack / eslint-plugin-compat

Check the browser compatibility of your code
MIT License
3.07k stars 104 forks source link

Might Miss Compatibility Issues Based on Assumed Polyfills from Babel Config #602

Open ChrisSargent opened 1 year ago

ChrisSargent commented 1 year ago

 Description

We use eslint-plugin-compat to check browser compatibility in our projects. However, we recently noticed some compatibility issues in our code related to Babel configurations and core-js.

For us, this happened specifically, when using the feature Object.hasOwn, which isn't supported in Safari < 15.3, we expected eslint-plugin-compat to flag this as an error. However, it seems the plugin checks for the presence of a Babel config and assumes that all possible polyfills for the browsers (defined in the browserslist file) are being used. This assumption can lead to false negatives, especially if there's a mismatch with the core-js version or if specific polyfills aren't explicitly imported.

This happened because we are using Gatsby and in the babel-preset-gatsby, it only use the major version for the corejs option, like corejs: 3 and recommendations from corejs repo says to use the minor version. I have created a PR against Gatsby to address this issue: https://github.com/gatsbyjs/gatsby/pull/38589/files

Potential Solutions

Honestly I'm not sure what could be done to address this in the logic / code - maybe detecting that @babel/preset-env is being used and checking the corejs version being passed in. Or maybe just something adding to the docs

Minimal Repo

https://github.com/ChrisSargent/eslint-compat-example