@@ -25,15 +25,26 @@ ruleTester.run("no-empty-character-class", rule, {
25
25
"var foo = /^abc/;" ,
26
26
"var foo = /[\\[]/;" ,
27
27
"var foo = /[\\]]/;" ,
28
+ "var foo = /\\[][\\]]/;" ,
28
29
"var foo = /[a-zA-Z\\[]/;" ,
29
30
"var foo = /[[]/;" ,
30
31
"var foo = /[\\[a-z[]]/;" ,
31
32
"var foo = /[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\^\\$\\|]/g;" ,
32
33
"var foo = /\\s*:\\s*/gim;" ,
34
+ "var foo = /[^]/;" , // this rule allows negated empty character classes
35
+ "var foo = /\\[][^]/;" ,
33
36
{ code : "var foo = /[\\]]/uy;" , parserOptions : { ecmaVersion : 6 } } ,
34
37
{ code : "var foo = /[\\]]/s;" , parserOptions : { ecmaVersion : 2018 } } ,
35
38
{ code : "var foo = /[\\]]/d;" , parserOptions : { ecmaVersion : 2022 } } ,
36
- "var foo = /\\[]/"
39
+ "var foo = /\\[]/" ,
40
+ { code : "var foo = /[[^]]/v;" , parserOptions : { ecmaVersion : 2024 } } ,
41
+ { code : "var foo = /[[\\]]]/v;" , parserOptions : { ecmaVersion : 2024 } } ,
42
+ { code : "var foo = /[[\\[]]/v;" , parserOptions : { ecmaVersion : 2024 } } ,
43
+ { code : "var foo = /[a--b]/v;" , parserOptions : { ecmaVersion : 2024 } } ,
44
+ { code : "var foo = /[a&&b]/v;" , parserOptions : { ecmaVersion : 2024 } } ,
45
+ { code : "var foo = /[[a][b]]/v;" , parserOptions : { ecmaVersion : 2024 } } ,
46
+ { code : "var foo = /[\\q{}]/v;" , parserOptions : { ecmaVersion : 2024 } } ,
47
+ { code : "var foo = /[[^]--\\p{ASCII}]/v;" , parserOptions : { ecmaVersion : 2024 } }
37
48
] ,
38
49
invalid : [
39
50
{ code : "var foo = /^abc[]/;" , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
@@ -43,6 +54,15 @@ ruleTester.run("no-empty-character-class", rule, {
43
54
{ code : "var foo = /[]]/;" , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
44
55
{ code : "var foo = /\\[[]/;" , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
45
56
{ code : "var foo = /\\[\\[\\]a-z[]/;" , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
46
- { code : "var foo = /[]]/d;" , parserOptions : { ecmaVersion : 2022 } , errors : [ { messageId : "unexpected" , type : "Literal" } ] }
57
+ { code : "var foo = /[]]/d;" , parserOptions : { ecmaVersion : 2022 } , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
58
+ { code : "var foo = /[(]\\u{0}*[]/u;" , parserOptions : { ecmaVersion : 2015 } , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
59
+ { code : "var foo = /[]/v;" , parserOptions : { ecmaVersion : 2024 } , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
60
+ { code : "var foo = /[[]]/v;" , parserOptions : { ecmaVersion : 2024 } , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
61
+ { code : "var foo = /[[a][]]/v;" , parserOptions : { ecmaVersion : 2024 } , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
62
+ { code : "var foo = /[a[[b[]c]]d]/v;" , parserOptions : { ecmaVersion : 2024 } , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
63
+ { code : "var foo = /[a--[]]/v;" , parserOptions : { ecmaVersion : 2024 } , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
64
+ { code : "var foo = /[[]--b]/v;" , parserOptions : { ecmaVersion : 2024 } , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
65
+ { code : "var foo = /[a&&[]]/v;" , parserOptions : { ecmaVersion : 2024 } , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
66
+ { code : "var foo = /[[]&&b]/v;" , parserOptions : { ecmaVersion : 2024 } , errors : [ { messageId : "unexpected" , type : "Literal" } ] }
47
67
]
48
68
} ) ;
0 commit comments