Skip to content

Commit fbf590d

Browse files
Add support for v flag to regexp/optimal-quantifier-concatenation (#618)
* Add support for `v` flag to `regexp/optimal-quantifier-concatenation` * Create beige-suns-clap.md
1 parent e973e28 commit fbf590d

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

.changeset/beige-suns-clap.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/optimal-quantifier-concatenation`

lib/rules/optimal-quantifier-concatenation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import type { Ancestor, ReadonlyFlags } from "regexp-ast-analysis"
1818
import {
1919
Chars,
2020
hasSomeDescendant,
21-
toCharSet,
2221
getConsumedChars,
22+
toUnicodeSet,
2323
} from "regexp-ast-analysis"
2424
import { getParser } from "../utils/regexp-ast"
2525
import type { CharSet } from "refa"
@@ -76,13 +76,13 @@ function getSingleConsumedChar(
7676
case "Character":
7777
case "CharacterSet":
7878
case "CharacterClass":
79-
case "ExpressionCharacterClass":
79+
case "ExpressionCharacterClass": {
80+
const set = toUnicodeSet(element, flags)
8081
return {
81-
// FIXME: TS Error
82-
// @ts-expect-error -- FIXME
83-
char: toCharSet(element, flags),
84-
complete: true,
82+
char: set.chars,
83+
complete: set.accept.isEmpty,
8584
}
85+
}
8686

8787
case "Group":
8888
case "CapturingGroup": {

tests/lib/rules/optimal-quantifier-concatenation.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import rule from "../../../lib/rules/optimal-quantifier-concatenation"
33

44
const tester = new RuleTester({
55
parserOptions: {
6-
ecmaVersion: 2020,
6+
ecmaVersion: "latest",
77
sourceType: "module",
88
},
99
})
@@ -291,5 +291,26 @@ tester.run("optimal-quantifier-concatenation", rule as any, {
291291
"'\\d*' can be removed because it is already included by '\\d+'. This cannot be fixed automatically because it involves a capturing group.",
292292
],
293293
},
294+
{
295+
code: String.raw`/\d+(\d*)/v`,
296+
output: null,
297+
errors: [
298+
"'\\d*' can be removed because it is already included by '\\d+'. This cannot be fixed automatically because it involves a capturing group.",
299+
],
300+
},
301+
{
302+
code: String.raw`/a+[a\q{}]+/v`,
303+
output: String.raw`/a+[a\q{}]/v`,
304+
errors: [
305+
"'[a\\q{}]+' can be replaced with '[a\\q{}]' because of 'a+'.",
306+
],
307+
},
308+
{
309+
code: String.raw`/[ab]*[\q{a|bb}]+/v`,
310+
output: String.raw`/[ab]*[\q{a|bb}]/v`,
311+
errors: [
312+
"'[\\q{a|bb}]+' can be replaced with '[\\q{a|bb}]' because of '[ab]*'.",
313+
],
314+
},
294315
],
295316
})

0 commit comments

Comments
 (0)