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
prefer-regex-literals: should report regex literals passed to RegExp constructor #12840
Comments
I think this makes sense. Not sure should it be new default behavior (breaking?) or an option. Should the rule also report
Did you mean "suggest" as the new Suggestions feature, or just the usual autofix? |
I support this proposal. I wonder if we should put this behind an option turned off by default even if we land this in the v7 major release and make it the default in a future major release. |
An option in v6, enabled in v7 would be ideal :-) waiting until v8 seems like a long time. |
@ljharb We're already in the alpha stage of releasing v7 and don't have any plans to do any more v6 releases. |
I was referring to the usual autofix.
I would say this should be reported as well. As long as both arguments are literals. Regarding whether this should be the default behavior or an option: I was really surprised to figure out the rule doesn’t already recognize this pattern, so maybe this could be even considered a bug. |
The rule `prefer-regex-literal` now detects when regex literals are unnecessarily passed to the `RegExp` constructor.
I guess we didn't consider disallowing This is a |
I'd also vote to start with an option instead of the default behavior. Although it isn't likely maybe there could be some use case for these. |
The rule `prefer-regex-literal` now detects when regex literals are unnecessarily passed to the `RegExp` constructor.
I’ve updated the PR and implemented the change behind a new option |
The rule `prefer-regex-literal` now detects when regex literals are unnecessarily passed to the `RegExp` constructor.
I'll champion this, only one more 👍 needed. |
@eslint/eslint-team We need one more 👍 to accept this. |
Done. Marked as accepted. |
The rule `prefer-regex-literal` now detects when regex literals are unnecessarily passed to the `RegExp` constructor.
The rule `prefer-regex-literal` now detects when regex literals are unnecessarily passed to the `RegExp` constructor.
What rule do you want to change?
prefer-regex-literals
Does this change cause the rule to produce more or fewer warnings?
It will produce more warnings.
How will the change be implemented? (New option, new default behavior, etc.)?
I think this makes sense as default behavior.
Please provide some example code that this change will affect:
What does the rule currently do for this code?
It is not recognized as a problem.
What will the rule do after it's changed?
The rule should report this as problem and suggest the following autofix:
Are you willing to submit a pull request to implement this change?
Yes
The text was updated successfully, but these errors were encountered: