-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
bugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have read the FAQ and my problem is not listed.
Repro
When used within a function whose arguments are passed to the new RegExp
constructor, the @typescript-eslint/prefer-regexp-exec
misfires.
function repro(pattern: string) {
"hello hello".match(new RegExp(pattern, "gi"))?.reduce(() => []);
}
Gets replaced to (when the eslint --fix
option is set):
function repro(pattern: string) {
new RegExp(pattern, "gi").exec("hello hello")?.reduce(() => []);
}
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
typescript 4.3.2
@typescript-eslint/eslint-plugin 4.25.0
@typescript-eslint/parser 4.25.0
eslint 7.27.0
philippendrulat and DanKaplanSES
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin