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
@typescript-eslint/prefer-regexp-exec
does not respect flags
#3477
Comments
Please ensure you use the issue templates when you file an issue by clicking the new issue template. Don't bypass the issue wizard by entering or changing the URL. Bypassing means you get the wrong issue template and your issue won't be automatically tagged. |
I used the template but removed some parts that didn't seem applicable. Is there any information you'd like me to add to the issue? |
Sorry, to clarify. If you create a new issue by clicking the "new issue" button on the Github UI it will take you to https://github.com/typescript-eslint/typescript-eslint/issues/new/choose, which is the issue wizard - through which you can choose an issue template workflow. But if you manually go to https://github.com/typescript-eslint/typescript-eslint/issues/new, then you will not go via the wizard, and you will get a catch-all template. Your issue will also not get automatically tagged. The lack of tags is why I know you did not go via the wizard. Always click the new issue button and follow the wizard to ensure you get the correct template and correct tags. |
I'd like to piggyback off of this because it's the closest thing to the issue I'm experiencing. It may actually be the same issue: const matchCount = (str: string, re: RegExp) => {
return (str.match(re) || []).length;
}; This triggers the error, but I don't think there's any way it could know if the re has a |
If #3855 gets in, this will be fixed as well. |
Repro
When used within a function whose arguments are passed to the
new RegExp
constructor, the@typescript-eslint/prefer-regexp-exec
misfires.Gets replaced to (when the
eslint --fix
option is set):This is an incorrect replacement because they are not equivalent due to the presence of the "g" flag.
Expected Result
The replacement shouldn't take place, the rule shouldn't error.
Actual Result
The rule returns an error and replaces the match if allowed to.
Additional Info
Versions
The text was updated successfully, but these errors were encountered: