Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_empty_character_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ fn test() {
("var foo = /[\\]]/s;", None),
("var foo = /[\\]]/d;", None),
("var foo = /\\[]/", None),
// ES2024
("var foo = /[[^]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[\\]]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[\\[]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[a--b]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[a&&b]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[a][b]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[\\q{}]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[^]--\\p{ASCII}]/v;", None), // { "ecmaVersion": 2024 }
];

let fail = vec![
Expand All @@ -143,6 +152,16 @@ fn test() {
("var foo = /[]]/d;", None),
("var foo = /[[][]]/v;", None),
("var foo = /[[]]|[]/v;", None),
("var foo = /[(]\\u{0}*[]/u;", None), // { "ecmaVersion": 2015 }
// ES2024
("var foo = /[]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[a][]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[a[[b[]c]]d]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[a--[]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[]--b]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[a&&[]]/v;", None), // { "ecmaVersion": 2024 }
("var foo = /[[]&&b]/v;", None), // { "ecmaVersion": 2024 }
];

Tester::new(NoEmptyCharacterClass::NAME, pass, fail).test_and_snapshot();
Expand Down
63 changes: 63 additions & 0 deletions crates/oxc_linter/src/snapshots/no_empty_character_class.snap
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,66 @@ source: crates/oxc_linter/src/tester.rs
· ──
╰────
help: Remove the empty character class: `[]`

⚠ eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:21]
1 │ var foo = /[(]\u{0}*[]/u;
· ──
╰────
help: Remove the empty character class: `[]`

⚠ eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:12]
1 │ var foo = /[]/v;
· ──
╰────
help: Remove the empty character class: `[]`

⚠ eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:13]
1 │ var foo = /[[]]/v;
· ──
╰────
help: Remove the empty character class: `[]`

⚠ eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:16]
1 │ var foo = /[[a][]]/v;
· ──
╰────
help: Remove the empty character class: `[]`

⚠ eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:17]
1 │ var foo = /[a[[b[]c]]d]/v;
· ──
╰────
help: Remove the empty character class: `[]`

⚠ eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:16]
1 │ var foo = /[a--[]]/v;
· ──
╰────
help: Remove the empty character class: `[]`

⚠ eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:13]
1 │ var foo = /[[]--b]/v;
· ──
╰────
help: Remove the empty character class: `[]`

⚠ eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:16]
1 │ var foo = /[a&&[]]/v;
· ──
╰────
help: Remove the empty character class: `[]`

⚠ eslint(no-empty-character-class): Empty character class will not match anything
╭─[no_empty_character_class.tsx:1:13]
1 │ var foo = /[[]&&b]/v;
· ──
╰────
help: Remove the empty character class: `[]`