Skip to content

Commit

Permalink
Add support for v flag to regexp/optimal-quantifier-concatenation (
Browse files Browse the repository at this point in the history
…#618)

* Add support for `v` flag to `regexp/optimal-quantifier-concatenation`

* Create beige-suns-clap.md
  • Loading branch information
RunDevelopment authored Oct 1, 2023
1 parent e973e28 commit fbf590d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-suns-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-regexp": minor
---

Add support for `v` flag to `regexp/optimal-quantifier-concatenation`
12 changes: 6 additions & 6 deletions lib/rules/optimal-quantifier-concatenation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import type { Ancestor, ReadonlyFlags } from "regexp-ast-analysis"
import {
Chars,
hasSomeDescendant,
toCharSet,
getConsumedChars,
toUnicodeSet,
} from "regexp-ast-analysis"
import { getParser } from "../utils/regexp-ast"
import type { CharSet } from "refa"
Expand Down Expand Up @@ -76,13 +76,13 @@ function getSingleConsumedChar(
case "Character":
case "CharacterSet":
case "CharacterClass":
case "ExpressionCharacterClass":
case "ExpressionCharacterClass": {
const set = toUnicodeSet(element, flags)
return {
// FIXME: TS Error
// @ts-expect-error -- FIXME
char: toCharSet(element, flags),
complete: true,
char: set.chars,
complete: set.accept.isEmpty,
}
}

case "Group":
case "CapturingGroup": {
Expand Down
23 changes: 22 additions & 1 deletion tests/lib/rules/optimal-quantifier-concatenation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import rule from "../../../lib/rules/optimal-quantifier-concatenation"

const tester = new RuleTester({
parserOptions: {
ecmaVersion: 2020,
ecmaVersion: "latest",
sourceType: "module",
},
})
Expand Down Expand Up @@ -291,5 +291,26 @@ tester.run("optimal-quantifier-concatenation", rule as any, {
"'\\d*' can be removed because it is already included by '\\d+'. This cannot be fixed automatically because it involves a capturing group.",
],
},
{
code: String.raw`/\d+(\d*)/v`,
output: null,
errors: [
"'\\d*' can be removed because it is already included by '\\d+'. This cannot be fixed automatically because it involves a capturing group.",
],
},
{
code: String.raw`/a+[a\q{}]+/v`,
output: String.raw`/a+[a\q{}]/v`,
errors: [
"'[a\\q{}]+' can be replaced with '[a\\q{}]' because of 'a+'.",
],
},
{
code: String.raw`/[ab]*[\q{a|bb}]+/v`,
output: String.raw`/[ab]*[\q{a|bb}]/v`,
errors: [
"'[\\q{a|bb}]+' can be replaced with '[\\q{a|bb}]' because of '[ab]*'.",
],
},
],
})

0 comments on commit fbf590d

Please sign in to comment.