-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrequire-unicode-regexp.ts
70 lines (65 loc) · 2.49 KB
/
require-unicode-regexp.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
59
60
61
62
63
64
65
66
67
68
69
70
import { SnapshotRuleTester } from "eslint-snapshot-rule-tester"
import rule from "../../../lib/rules/require-unicode-regexp"
const tester = new SnapshotRuleTester({
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
globals: {
globalThis: "off",
},
},
})
tester.run("require-unicode-regexp", rule as any, {
valid: [
String.raw`/foo/u`,
String.raw`/foo/gimuy`,
String.raw`RegExp('', 'u')`,
String.raw`new RegExp('', 'u')`,
String.raw`RegExp('', 'gimuy')`,
String.raw`new RegExp('', 'gimuy')`,
String.raw`const flags = 'u'; new RegExp('', flags)`,
String.raw`const flags = 'g'; new RegExp('', flags + 'u')`,
String.raw`const flags = 'gimu'; new RegExp('foo', flags[3])`,
String.raw`new RegExp('', flags)`,
String.raw`function f(flags) { return new RegExp('', flags) }`,
String.raw`function f(RegExp) { return new RegExp('foo') }`,
String.raw`new globalThis.RegExp('foo')`,
String.raw`new globalThis.RegExp('foo', 'u')`,
String.raw`globalThis.RegExp('foo', 'u')`,
String.raw`const flags = 'u'; new globalThis.RegExp('', flags)`,
String.raw`const flags = 'g'; new globalThis.RegExp('', flags + 'u')`,
String.raw`const flags = 'gimu'; new globalThis.RegExp('foo', flags[3])`,
String.raw`/foo/v`,
String.raw`new RegExp('foo', 'v')`,
],
invalid: [
String.raw`/foo/`,
String.raw`/foo/gimy`,
String.raw`RegExp('foo')`,
String.raw`RegExp('foo', '')`,
String.raw`RegExp('foo', 'gimy')`,
String.raw`new RegExp('foo')`,
String.raw`new RegExp('foo', '')`,
String.raw`new RegExp('foo', 'gimy')`,
String.raw`const flags = 'gi'; new RegExp('foo', flags)`,
String.raw`const flags = 'gimu'; new RegExp('foo', flags[0])`,
// Compatibility
// All of the below cases are only fixable if they are compatible
String.raw`/❤️/`,
String.raw`/foo/i`,
String.raw`/ab+c/`,
String.raw`/a.*b/`,
String.raw`/<[^<>]+>/`,
// "k" maps to 3 characters in ignore-case Unicode mode
String.raw`/k/i`,
// Same for \w
String.raw`/\w/i`,
// Same for \b
String.raw`/\bfoo/i`,
String.raw`/[😃]/`,
String.raw`/😃+/`,
String.raw`/\p{Ll}/`,
// "<😃>" is accepted by one but not the other
String.raw`/<[^<>]>/`,
],
})