-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprefer-set-operation.ts
42 lines (40 loc) · 1.12 KB
/
prefer-set-operation.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
import { RuleTester } from "eslint"
import rule from "../../../lib/rules/prefer-set-operation"
const tester = new RuleTester({
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
})
tester.run("prefer-set-operation", rule as any, {
valid: [
String.raw`/a\b/`,
String.raw`/a\b/u`,
String.raw`/a\b/v`,
String.raw`/(?!a)\w/`,
String.raw`/(?!a)\w/u`,
],
invalid: [
{
code: String.raw`/(?!a)\w/v`,
output: String.raw`/[\w--a]/v`,
errors: [
"This lookaround can be combined with '\\w' using a set operation.",
],
},
{
code: String.raw`/\w(?<=\d)/v`,
output: String.raw`/[\w&&\d]/v`,
errors: [
"This lookaround can be combined with '\\w' using a set operation.",
],
},
{
code: String.raw`/(?!-)&/v`,
output: String.raw`/[\&--\-]/v`,
errors: [
"This lookaround can be combined with '&' using a set operation.",
],
},
],
})