`prefer-lookaround` Not checking groups contains negate CharacterClass
fisker opened this issue · comments
fisker Cheung commented
Information:
- ESLint version: 8.27.0
eslint-plugin-regexp
version: 7.31.10
Description
'ab'.replaceAll(/a([b])/g, "$1");
'ac'.replaceAll(/a([^b])/g, "$1");
The first is reported.
The second is not, it should be able to fix to
'ac'.replaceAll(/a(?=[^b])/g, "");
Yosuke Ota commented
Thank you for posting issue.
But, it's an intentional behavior.
Replacing it with lookahead has the side effect of not consuming any characters.
'aaaaa'.replaceAll(/a([^b])/g, ",$1");
// ',a,aa'
'aaaaa'.replaceAll(/a(?=[^b])/g, ",");
// ',,,,a'
The following negated character classes are reported because they have no side effects when replaced with lookahead.
'ac'.replaceAll(/a([^a])/g, "$1");
fisker Cheung commented
Thanks for the information.