Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow-listing syntax rules, like is already possible for polyfills #95

Open
niklaas opened this issue Jan 29, 2024 · 4 comments
Open

Allow-listing syntax rules, like is already possible for polyfills #95

niklaas opened this issue Jan 29, 2024 · 4 comments
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@niklaas
Copy link

niklaas commented Jan 29, 2024

Is there a way to whitelist any rule i.e., not only the ones there are polyfills for? In my use case, I would like the plugin to enforce according the browserslist but whitelist the no-rest-spread-properties rule:

{
ruleConfig: { definition: esPlugin.rules['no-rest-spread-properties'] },
compatFeatures: [
compatData.javascript.operators.destructuring.rest_in_objects,
compatData.javascript.operators.spread.spread_in_object_literals,
],
},

@robatwilliams
Copy link
Owner

Not at the moment. What do you need this for?

@niklaas
Copy link
Author

niklaas commented Jan 30, 2024

Not at the moment. What do you need this for?

I just joined a codebase that's a Ruby-React-Angular creature with a custom build. I fell into the trap of adding a regular expression look-behind causing a regression because some of the older browser versions we want to support don't support that feature.

Since the browsers we want to support are documented well in the browserslist file, I came across this repository, adding the recommended rules accordingly. I now get my look-behind flagged but also a lot of other false positives that are actually dealt with by the build system.

Since I cannot whitelist any rule, I had to circumvent the false positives by using the eslint-plugin-es-x directly. However, I would prefer using this plugin instead since it wouldn't require me to remember to update the rules myself as soon as we change the browserslist.

Does that make sense? Why would you allow to whitelist rules there are polyfills for only?

@robatwilliams
Copy link
Owner

robatwilliams commented Jan 30, 2024

but also a lot of other false positives that are actually dealt with by the build system

In this case I recommend you lint your build output rather than your source code. Linting it with just this plugin and no other rules.

I had documented some example usages here but you have brought up a new one I will document: using the plugin to check that the transpiler configuration is adequate for the supported browsers.

Why would you allow to whitelist rules there are polyfills for only?

Polyfills are compatible with all browsers, so can be used to uplift supported features. Syntax (like in your example) must be transpiled or it'll cause a parsing error in the browser - there is no usefulness I see in being able to list these as exceptions; I envisage that for your purpose you lint the build output.

@robatwilliams robatwilliams changed the title Whitelisting any rule Allow-listing syntax rules, like is already possible for polyfills Jan 30, 2024
@robatwilliams robatwilliams added documentation Improvements or additions to documentation question Further information is requested labels Jan 30, 2024
@niklaas
Copy link
Author

niklaas commented Jan 31, 2024

In this case I recommend you lint your build output rather than your source code. Linting it with just this plugin and no other rules.

Ah. That's an interesting solution I haven't thought of! I think it does come with one trade-off though: The feedback loop for the developers is shorter because they won't see errors lighting up in their IDEs while coding. They will only see them when they light up in the CI/CD checks.

Anyway, linting the final build seems the best way to ensure that the shipped code doesn't contain any unsupported features. Who knows what the build system does to the code when it's transpiled? 👍🏼

I think we'll go with a two-gate set-up: First, we use eslint-plugin-es-x to flag particular rules while coding; and, second, we use eslint-plugin-ecmascript-compat to check the compiled code.

Thanks for sharing your thoughts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants