-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathno-trivially-nested-assertion.ts
58 lines (52 loc) · 1.62 KB
/
no-trivially-nested-assertion.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { SnapshotRuleTester } from "eslint-snapshot-rule-tester"
import rule from "../../../lib/rules/no-trivially-nested-assertion"
const tester = new SnapshotRuleTester({
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
})
tester.run("no-trivially-nested-assertion", rule as any, {
valid: [
`/(?=(?=a)b)/`,
// these anchors cannot be negated, so they have to be allowed
`/(?!$)/`,
`/(?<!$)/`,
`/(?!^)/`,
`/(?<!^)/`,
// the text of capturing groups inside negated lookarounds is
// guaranteed to be reset, so we can't transform them into one
// non-negated lookaround
`/(?!(?!(a)))/`,
// ES2024
String.raw`/(?=[\q{$}])/v`,
],
invalid: [
String(/(?=$)/),
String(/(?=^)/),
String(/(?<=$)/),
String(/(?<=^)/),
String(/(?=\b)/),
String(/(?!\b)/),
String(/(?<=\b)/),
String(/(?<!\b)/),
// all trivially nested lookarounds can be written as one lookaround
// Note: The inner lookaround has to be negated if the outer one is negative.
String(/(?=(?=a))/),
String(/(?=(?!a))/),
String(/(?=(?<=a))/),
String(/(?=(?<!a))/),
String(/(?!(?=a))/),
String(/(?!(?!a))/),
String(/(?!(?<=a))/),
String(/(?!(?<!a))/),
String(/(?<=(?=a))/),
String(/(?<=(?!a))/),
String(/(?<=(?<=a))/),
String(/(?<=(?<!a))/),
String(/(?<!(?=a))/),
String(/(?<!(?!a))/),
String(/(?<!(?<=a))/),
String(/(?<!(?<!a))/),
],
})