-
-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy patheslint.config.mjs
More file actions
85 lines (81 loc) · 3.23 KB
/
Copy patheslint.config.mjs
File metadata and controls
85 lines (81 loc) · 3.23 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
// Lint setup for the runtime's builtin JavaScript
// (test-app/runtime/src/main/cpp/js). Each file is compiled by BuiltinLoader
// as a FUNCTION BODY with the fixed parameters `exports`, `require`, `module`,
// `binding` and `primordials` (see that directory's README.md), which are
// declared as globals here. no-undef is the typo net for binding-bag destructures and
// native-global usage alike; no-restricted-properties keeps the captured
// intrinsics from being read off the live globals again.
import globals from 'globals';
// Statics that primordials.js captures, mapped to their replacement. Instance
// methods (Array.prototype.slice and friends) cannot be matched by
// no-restricted-properties on the receiver, so uncurried use of those stays a
// review rule.
const capturedStatics = [
['Array', 'isArray', 'ArrayIsArray'],
['ArrayBuffer', 'isView', 'ArrayBufferIsView'],
['JSON', 'stringify', 'JSONStringify'],
['Number', 'isNaN', 'NumberIsNaN'],
['Number', 'parseFloat', 'NumberParseFloat'],
['Number', 'parseInt', 'NumberParseInt'],
['Object', 'create', 'ObjectCreate'],
['Object', 'defineProperty', 'ObjectDefineProperty'],
['Object', 'freeze', 'ObjectFreeze'],
['Object', 'getOwnPropertyDescriptor', 'ObjectGetOwnPropertyDescriptor'],
['Object', 'getOwnPropertySymbols', 'ObjectGetOwnPropertySymbols'],
['Object', 'getPrototypeOf', 'ObjectGetPrototypeOf'],
['Object', 'is', 'ObjectIs'],
['Object', 'keys', 'ObjectKeys'],
];
// Captured constructors. A destructure from `primordials` shadows the global,
// so these only fire on the unguarded reference.
const restrictedGlobals = ['Date', 'Map', 'Number', 'Proxy', 'Set', 'String', 'TypeError'].map((name) => ({
name,
message: `Destructure ${name} from primordials — builtins must not read intrinsics off globals user code can replace.`,
}));
const restrictedProperties = capturedStatics.map(([object, property, primordial]) => ({
object,
property,
message: `Use the ${primordial} primordial instead of ${object}.${property} — builtins must not read intrinsics off globals user code can replace.`,
}));
export default [
{
files: ['test-app/runtime/src/main/cpp/js/**/*.js'],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'script',
globals: {
...globals.es2021,
exports: 'readonly',
require: 'readonly',
module: 'readonly',
binding: 'readonly',
primordials: 'readonly',
global: 'readonly',
console: 'readonly',
URL: 'readonly',
URLSearchParams: 'readonly',
Blob: 'readonly',
File: 'readonly',
WebAssembly: 'readonly',
// Java package roots resolved through the metadata interceptor at
// runtime:
java: 'readonly',
org: 'readonly',
},
},
rules: {
'no-undef': 'error',
'no-unused-vars': ['error', { args: 'none', caughtErrors: 'none' }],
'no-restricted-properties': ['error', ...restrictedProperties],
'no-restricted-globals': ['error', ...restrictedGlobals],
},
},
{
// The file that does the capturing.
files: ['test-app/runtime/src/main/cpp/js/primordials.js'],
rules: {
'no-restricted-properties': 'off',
'no-restricted-globals': 'off',
},
},
];