Repository navigation
Expand file tree
/
Copy patheslint.runtime-guard.config.mjs
More file actions
112 lines (105 loc) · 2.8 KB
/
Copy patheslint.runtime-guard.config.mjs
File metadata and controls
112 lines (105 loc) · 2.8 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Runtime-error guard for the JavaScript that Android injects into the Hermes
// WebUI WebView (see tools/extract_webui_scripts.py).
//
// Deliberately NOT a style linter: no formatting, naming, or complexity rules.
// It enables only the rules that catch code which parses fine but throws when a
// real WebView executes it — the class of bug that bricks WebUI rendering on
// device while every Kotlin unit test and Android Lint check stays green.
const browserGlobals = [
"AbortController",
"Blob",
"ClipboardEvent",
"ClipboardItem",
"DataTransfer",
"File",
"atob",
"CSS",
"CustomEvent",
"DOMException",
"Date",
"Element",
"Event",
"FormData",
"Headers",
"HTMLElement",
"Image",
"JSON",
"Math",
"MediaRecorder",
"MutationObserver",
"Node",
"NodeFilter",
"Notification",
"Promise",
"Request",
"Response",
"ResizeObserver",
"ServiceWorkerRegistration",
"URL",
"URLSearchParams",
"cancelAnimationFrame",
"clearInterval",
"clearTimeout",
"console",
"document",
"fetch",
"getComputedStyle",
"localStorage",
"location",
"navigator",
"queueMicrotask",
"requestAnimationFrame",
"screen",
"self",
"sessionStorage",
"setInterval",
"setTimeout",
"visualViewport",
"window",
];
// Globals owned by the Hermes WebUI page itself, not by Android. The shims read
// them defensively (`typeof x !== 'undefined'`) because WebUI may rename or drop
// them; list them here so no-undef stays meaningful for genuine typos.
const webUiPageGlobals = ["_clarifyId", "_clarifySignature", "S"];
const globals = Object.fromEntries(
[...browserGlobals, ...webUiPageGlobals].map((name) => [name, "readonly"]),
);
export default [
{
files: ["**/*.js"],
languageOptions: {
ecmaVersion: 2020,
sourceType: "script",
globals,
},
linterOptions: {
reportUnusedDisableDirectives: true,
},
rules: {
// Assignment/binding errors that throw only at execution time.
"no-const-assign": "error",
"no-import-assign": "error",
"no-func-assign": "error",
"no-class-assign": "error",
"no-self-assign": "error",
// References that resolve to nothing once the browser runs the script.
"no-undef": "error",
"no-obj-calls": "error",
"no-unreachable": "error",
// Silent-wrong-behavior traps.
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-dupe-class-members": "error",
"no-duplicate-case": "error",
"no-unsafe-negation": "error",
"no-unsafe-finally": "error",
"no-compare-neg-zero": "error",
"use-isnan": "error",
"valid-typeof": "error",
// Declaration hazards specific to the classic-script scope these run in.
"no-redeclare": "error",
"no-undef-init": "off",
"no-sparse-arrays": "error",
},
},
];