Skip to content

Commit 0eedddf

Browse files
Add support for v flag to regexp/no-contradiction-with-assertion
1 parent bc56ef0 commit 0eedddf

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/rules/no-contradiction-with-assertion.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ function* getNextElements(
8989

9090
if (
9191
parent.type === "CharacterClass" ||
92-
parent.type === "CharacterClassRange"
92+
parent.type === "CharacterClassRange" ||
93+
parent.type === "ExpressionCharacterClass" ||
94+
parent.type === "ClassIntersection" ||
95+
parent.type === "ClassSubtraction" ||
96+
parent.type === "StringAlternative"
9397
) {
9498
return
9599
}
@@ -103,10 +107,8 @@ function* getNextElements(
103107
}
104108
}
105109

106-
// FIXME: TS Error
107-
// @ts-expect-error -- FIXME
108110
const elements = parent.elements
109-
const index = elements.indexOf(element) as number
111+
const index = elements.indexOf(element)
110112
const inc = dir === "ltr" ? 1 : -1
111113
for (let i = index + inc; i >= 0 && i < elements.length; i += inc) {
112114
const e = elements[i]

tests/lib/rules/no-contradiction-with-assertion.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import rule from "../../../lib/rules/no-contradiction-with-assertion"
33

44
const tester = new RuleTester({
55
parserOptions: {
6-
ecmaVersion: 2020,
6+
ecmaVersion: "latest",
77
sourceType: "module",
88
},
99
})
@@ -15,10 +15,12 @@ tester.run("no-contradiction-with-assertion", rule as any, {
1515
String.raw`/(?!)a/`,
1616
String.raw`/(?=)a/`,
1717
String.raw`/$a/`,
18+
String.raw`/$a/v`,
1819

1920
// Other valid regexes
2021
String.raw`/(^|[\s\S])\bfoo/`,
2122
String.raw`/(?:aa|a\b)-?a/`,
23+
String.raw`/(?:aa|a\b)-?a/v`,
2224
],
2325
invalid: [
2426
{
@@ -48,6 +50,15 @@ tester.run("no-contradiction-with-assertion", rule as any, {
4850
},
4951
],
5052
},
53+
{
54+
code: String.raw`/a\b[a\q{foo|bar}]*-/v`,
55+
errors: [
56+
{
57+
messageId: "cannotEnterQuantifier",
58+
suggestions: [{ output: String.raw`/a\b-/v` }],
59+
},
60+
],
61+
},
5162

5263
{
5364
code: String.raw`/(^[\t ]*)#(?:comments-start|cs)[\s\S]*?^[ \t]*#(?:comments-end|ce)/m`,

0 commit comments

Comments
 (0)