@@ -25,15 +25,26 @@ ruleTester.run("no-empty-character-class", rule, {
2525 "var foo = /^abc/;" ,
2626 "var foo = /[\\[]/;" ,
2727 "var foo = /[\\]]/;" ,
28+ "var foo = /\\[][\\]]/;" ,
2829 "var foo = /[a-zA-Z\\[]/;" ,
2930 "var foo = /[[]/;" ,
3031 "var foo = /[\\[a-z[]]/;" ,
3132 "var foo = /[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\\\^\\$\\|]/g;" ,
3233 "var foo = /\\s*:\\s*/gim;" ,
34+ "var foo = /[^]/;" , // this rule allows negated empty character classes
35+ "var foo = /\\[][^]/;" ,
3336 { code : "var foo = /[\\]]/uy;" , parserOptions : { ecmaVersion : 6 } } ,
3437 { code : "var foo = /[\\]]/s;" , parserOptions : { ecmaVersion : 2018 } } ,
3538 { 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 } }
3748 ] ,
3849 invalid : [
3950 { code : "var foo = /^abc[]/;" , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
@@ -43,6 +54,15 @@ ruleTester.run("no-empty-character-class", rule, {
4354 { code : "var foo = /[]]/;" , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
4455 { code : "var foo = /\\[[]/;" , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
4556 { 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" } ] }
4767 ]
4868} ) ;
0 commit comments