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

no-invalid-regexp should catch non-cross-platform regex features #11931

Closed
Daniel15 opened this issue Jul 1, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@Daniel15
Copy link
Contributor

commented Jul 1, 2019

What rule do you want to change?
no-invalid-regexp

Does this change cause the rule to produce more or fewer warnings?
More

How will the change be implemented? (New option, new default behavior, etc.)?
New option

Please provide some example code that this change will affect:

const namedCaptureGroupsExample = /^(?<foo>.+)/;
const lookBehindExample = /(?<=[a-z])(?=[A-Z])/g;

This uses regex feature (named capture groups and lookbehind) that are only supported in some browsers: https://www.smashingmagazine.com/2019/02/regexp-features-regular-expressions/. Firefox actually throws a syntax error for this.

What does the rule currently do for this code?
Nothing

What will the rule do after it's changed?
Error: Named capture groups are not supported in all browsers
Error: Lookbehind is not supported in all browsers

Are you willing to submit a pull request to implement this change?
Maybe, if this proposal sounds OK

@platinumazure

This comment has been minimized.

Copy link
Member

commented Jul 1, 2019

Hi @Daniel15, thanks for the issue!

I don't think we can put in options for specific runtimes, but we might be able to put in options for allowing or disallowing specific regex features. Do you have any thoughts on what options we should add?

@platinumazure platinumazure added evaluating and removed triage labels Jul 1, 2019

@Daniel15

This comment has been minimized.

Copy link
Contributor Author

commented Jul 1, 2019

Do you have any thoughts on what options we should add?

At least all the features that Firefox doesn't currently support. I know of the two examples in my post, but there could be others.

At FB, we've had breakages in some internal tools due to usage of regex features that Firefox doesn't support. Unfortunately, these are syntax errors in Firefox, meaning they break the entire script at parse time 😢

@mysticatea

This comment has been minimized.

Copy link
Member

commented Jul 1, 2019

You may be interested in eslint-plugin-es. It allows us to disable each syntax individually.

@Daniel15

This comment has been minimized.

Copy link
Contributor Author

commented Jul 2, 2019

Thank you @mysticatea - That is perfect!! Just enabled these rules in my ESLint config, as I verified that they're all syntax errors in the latest Firefox:

'es/no-regexp-lookbehind-assertions'
'es/no-regexp-named-capture-groups'
'es/no-regexp-s-flag'
'es/no-regexp-unicode-property-escapes'

Since these rules exist, I guess this issue can be closed.

@Daniel15 Daniel15 closed this Jul 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.