Skip to content

Commit 3757a92

Browse files
committed
fix
1 parent 155f057 commit 3757a92

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

lib/rules/require-unicode-sets-regexp.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@ import { createRule, defineRegexpVisitor } from "../utils"
44
import { RegExpParser, visitRegExpAST } from "@eslint-community/regexpp"
55
import { toUnicodeSet } from "regexp-ast-analysis"
66

7+
const CLASS_SET_RESERVED_DOUBLE_PUNCTUATORS = [
8+
"&&",
9+
"!!",
10+
"##",
11+
"$$",
12+
"%%",
13+
"**",
14+
"++",
15+
",,",
16+
"..",
17+
"::",
18+
";;",
19+
"<<",
20+
"==",
21+
">>",
22+
"??",
23+
"@@",
24+
"^^",
25+
"``",
26+
"~~",
27+
"--",
28+
]
29+
730
/**
831
* Returns whether the regex would keep its behavior if the v flag were to be
932
* added.
@@ -25,6 +48,13 @@ function isCompatible(regexpContext: RegExpContext): boolean {
2548
if (!us.equals(vus)) {
2649
throw INCOMPATIBLE
2750
}
51+
if (
52+
CLASS_SET_RESERVED_DOUBLE_PUNCTUATORS.some((punctuator) =>
53+
node.raw.includes(punctuator),
54+
)
55+
) {
56+
throw INCOMPATIBLE
57+
}
2858
},
2959
})
3060
} catch (error) {

tests/lib/rules/require-unicode-sets-regexp.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,35 @@ tester.run("require-unicode-sets-regexp", rule as any, {
4646
output: null, // Converting to the v flag changes the behavior of the character set.
4747
errors: ["Use the 'v' flag."],
4848
},
49+
...[
50+
"&&",
51+
"!!",
52+
"##",
53+
"$$",
54+
"%%",
55+
"**",
56+
"++",
57+
",,",
58+
"..",
59+
"::",
60+
";;",
61+
"<<",
62+
"==",
63+
">>",
64+
"??",
65+
"@@",
66+
"^^",
67+
"``",
68+
"~~",
69+
].map((punctuator) => ({
70+
code: String.raw`/[a${punctuator}b]/u`,
71+
output: null, // Converting to the v flag changes the behavior of the character set.
72+
errors: ["Use the 'v' flag."],
73+
})),
74+
{
75+
code: String.raw`/[+--b]/u`,
76+
output: null, // Converting to the v flag changes the behavior of the character set.
77+
errors: ["Use the 'v' flag."],
78+
},
4979
],
5080
})

0 commit comments

Comments
 (0)