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
New rule proposal: prefer-regex-literals #12238
New rule proposal: prefer-regex-literals #12238
Comments
Yes! I really want to see this in core. 👍 from me. |
How about |
That style indeed doesn't have the problem with double escapes. First idea was to disallow just string literals (maybe also simple template literals used as strings), but since the rule is |
Yes, I think so. |
I agree! Working on this. |
Please describe what the rule should do:
Suggests to use regex literals instead of
RegExp()
/new RegExp()
when these calls have:What category of rule is this? (place an "X" next to just one item)
[X] Suggests an alternate way of doing something (suggestion)
Provide 2-3 code examples that this rule will warn about:
Why should this rule be included in ESLint (instead of a plugin)?
I think this is not just a style preference, rather a good practice to avoid an unnecessary level of the string literal syntax on top of the regex syntax. It's error-prone and difficult to reason about escapes of escapes.
Are you willing to submit a pull request to implement this rule?
Yes.
The text was updated successfully, but these errors were encountered: