-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprefer-regexp-exec.ts
51 lines (44 loc) · 1.14 KB
/
prefer-regexp-exec.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
import { SnapshotRuleTester } from "eslint-snapshot-rule-tester"
import rule from "../../../lib/rules/prefer-regexp-exec"
const tester = new SnapshotRuleTester({
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
})
tester.run("prefer-regexp-exec", rule as any, {
valid: [
`
/thing/.exec('something');
'some things are just things'.match(/thing/g);
const text = 'something';
const search = /thing/;
search.exec(text);
`,
`
/thin[[g]]/v.exec('something');
`,
],
invalid: [
`
'something'.match(/thing/);
'some things are just things'.match(/thing/);
const text = 'something';
const search = /thing/;
text.match(search);
`,
`
const fn = (a) => a + ''
fn(1).match(search);
`,
`
const v = a + b
v.match(search);
const n = 1 + 2
n.match(search); // ignore
`,
`
'something'.match(/thin[[g]]/v);
`,
],
})