robatwilliams / es-compat

*** DEPRECATED*** Check JavaScript code compatibility with target runtime environments
MIT License
66 stars 13 forks source link

Ignore usages that are part of feature test expressions #72

Open robatwilliams opened 1 year ago

robatwilliams commented 1 year ago

If your code (or library code) is using a feature support test conditional statement before using a feature, then you still get an error reported by this plugin. It doesn't know your intent when doing such checks.

The current workaround is to configure the options to say you have a polyfill for that feature, even if you don't. This is dangerous as it will ignore all usages of that feature, including those without a feature test guard. This workaround isn't an option for non-polyfillable features namely BigInt and Atomics, as raised in #70.

It's the responsibility of https://github.com/eslint-community/eslint-plugin-es-x to do the detection. es-compat simply passes through all reports raised by it.

It might be possible to implement something here to guess if an expression looks like a feature test. We have the AST node there. But really eslint-plugin-es-x would be the ideal place for this, as this problem is not unique to es-compat, and it's the root of where the problem arises.

robatwilliams commented 1 year ago

This is a partly a subset of #29

robatwilliams commented 1 year ago

Example of workaround: https://github.com/livekit/client-sdk-js/blob/b90aa3311130a594067f48de2daac9b0ce97e7ea/.eslintrc.dist.cjs#L11

robatwilliams commented 11 months ago

A smaller scope solution could allow users to specify code strings to ignore as a rule option. We might be able to think of many possible ways of doing feature tests, but not all.