Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Sep 15, 2023
1 parent 155f057 commit 3757a92
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/rules/require-unicode-sets-regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ import { createRule, defineRegexpVisitor } from "../utils"
import { RegExpParser, visitRegExpAST } from "@eslint-community/regexpp"
import { toUnicodeSet } from "regexp-ast-analysis"

const CLASS_SET_RESERVED_DOUBLE_PUNCTUATORS = [
"&&",
"!!",
"##",
"$$",
"%%",
"**",
"++",
",,",
"..",
"::",
";;",
"<<",
"==",
">>",
"??",
"@@",
"^^",
"``",
"~~",
"--",
]

/**
* Returns whether the regex would keep its behavior if the v flag were to be
* added.
Expand All @@ -25,6 +48,13 @@ function isCompatible(regexpContext: RegExpContext): boolean {
if (!us.equals(vus)) {
throw INCOMPATIBLE
}
if (
CLASS_SET_RESERVED_DOUBLE_PUNCTUATORS.some((punctuator) =>
node.raw.includes(punctuator),
)
) {
throw INCOMPATIBLE
}
},
})
} catch (error) {
Expand Down
30 changes: 30 additions & 0 deletions tests/lib/rules/require-unicode-sets-regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,35 @@ tester.run("require-unicode-sets-regexp", rule as any, {
output: null, // Converting to the v flag changes the behavior of the character set.
errors: ["Use the 'v' flag."],
},
...[
"&&",
"!!",
"##",
"$$",
"%%",
"**",
"++",
",,",
"..",
"::",
";;",
"<<",
"==",
">>",
"??",
"@@",
"^^",
"``",
"~~",
].map((punctuator) => ({
code: String.raw`/[a${punctuator}b]/u`,
output: null, // Converting to the v flag changes the behavior of the character set.
errors: ["Use the 'v' flag."],
})),
{
code: String.raw`/[+--b]/u`,
output: null, // Converting to the v flag changes the behavior of the character set.
errors: ["Use the 'v' flag."],
},
],
})

0 comments on commit 3757a92

Please sign in to comment.