Skip to content

Commit

Permalink
fix(noUselessEscapeInRegex): don't report unescaped range sep at the …
Browse files Browse the repository at this point in the history
…end of a class (#3687)
  • Loading branch information
Conaclos authored Aug 20, 2024
1 parent 2ed2cb9 commit 7fce9af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ impl Rule for NoUselessEscapeInRegex {
b']' => {
if has_v_flag && inner_class_count != 0 {
inner_class_count -= 1;
} else if !has_v_flag && bytes[index - 1] == b'-' {
} else if !has_v_flag
&& bytes[index - 2] == b'\\'
&& bytes[index - 1] == b'-'
{
return Some(State {
backslash_index: (index - 2) as u16,
escaped: b'-',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,6 @@
/[_^\^]/v;
/[\&&&\&]/v;
/[[\-]\-]/v;
/[\^]/v;
/[\^]/v;

/[z-]/;
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ expression: valid.js
/[\&&&\&]/v;
/[[\-]\-]/v;
/[\^]/v;

/[z-]/;

```

0 comments on commit 7fce9af

Please sign in to comment.