Skip to content

Commit bf67254

Browse files
authored
Add support for v flag to regexp/no-empty-character-class (#637)
1 parent 36ebbb7 commit bf67254

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

.changeset/purple-suns-carry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-regexp": minor
3+
---
4+
5+
Add support for v flag to `regexp/no-empty-character-class`

lib/rules/no-empty-character-class.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ export default createRule("no-empty-character-class", {
3535
})
3636
}
3737
},
38+
onExpressionCharacterClassEnter(ccNode) {
39+
if (matchesNoCharacters(ccNode, flags)) {
40+
context.report({
41+
node,
42+
loc: getRegexpLocation(ccNode),
43+
messageId: "cannotMatchAny",
44+
})
45+
}
46+
},
3847
}
3948
}
4049

tests/lib/rules/no-empty-character-class.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import rule from "../../../lib/rules/no-empty-character-class"
33

44
const tester = new RuleTester({
55
parserOptions: {
6-
ecmaVersion: 2020,
6+
ecmaVersion: "latest",
77
sourceType: "module",
88
},
99
})
@@ -21,6 +21,8 @@ tester.run("no-empty-character-class", rule as any, {
2121
`/[ ]/`,
2222
String.raw`/[\s\S]/`,
2323
String.raw`/[\da-zA-Z_\W]/`,
24+
String.raw`/a[[[ab]&&b]]/v`,
25+
String.raw`/a[[ab]&&b]/v`,
2426
],
2527
invalid: [
2628
{
@@ -75,5 +77,33 @@ tester.run("no-empty-character-class", rule as any, {
7577
code: String.raw`/[^\da-zA-Z_\W]/`,
7678
errors: ["This character class cannot match any characters."],
7779
},
80+
{
81+
code: String.raw`/a[[a&&b]]/v`,
82+
errors: [
83+
{
84+
message:
85+
"This character class cannot match any characters.",
86+
line: 1,
87+
column: 3,
88+
},
89+
{
90+
message:
91+
"This character class cannot match any characters.",
92+
line: 1,
93+
column: 4,
94+
},
95+
],
96+
},
97+
{
98+
code: String.raw`/a[a&&b]/v`,
99+
errors: [
100+
{
101+
message:
102+
"This character class cannot match any characters.",
103+
line: 1,
104+
column: 3,
105+
},
106+
],
107+
},
78108
],
79109
})

0 commit comments

Comments
 (0)