-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy patheslint.config.mjs
More file actions
108 lines (104 loc) · 4.31 KB
/
Copy patheslint.config.mjs
File metadata and controls
108 lines (104 loc) · 4.31 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
// Lint setup for the runtime's builtin JavaScript (NativeScript/runtime/js).
// Each file is compiled by BuiltinLoader as a FUNCTION BODY with the fixed
// parameters `exports`, `module`, `binding` and `primordials` (see
// NativeScript/runtime/js/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', 'parseFloat', 'NumberParseFloat'],
['Number', 'parseInt', 'NumberParseInt'],
['Object', 'assign', 'ObjectAssign'],
['Object', 'create', 'ObjectCreate'],
['Object', 'defineProperty', 'ObjectDefineProperty'],
['Object', 'freeze', 'ObjectFreeze'],
['Object', 'getOwnPropertyDescriptor', 'ObjectGetOwnPropertyDescriptor'],
['Object', 'getOwnPropertySymbols', 'ObjectGetOwnPropertySymbols'],
['Object', 'getPrototypeOf', 'ObjectGetPrototypeOf'],
['Object', 'is', 'ObjectIs'],
['Object', 'keys', 'ObjectKeys'],
['Object', 'setPrototypeOf', 'ObjectSetPrototypeOf'],
['Reflect', 'construct', 'ReflectConstruct'],
// No ReflectApply primordial: apply goes through the uncurried
// Function.prototype.apply, which is one property read cheaper.
['Reflect', 'apply', 'FunctionPrototypeApply'],
];
// Captured constructors and namespaces. A destructure from `primordials`
// shadows the global, so these only fire on the unguarded reference.
// `Array` and `Reflect` are deliberately absent: builtins still use them bare
// (`instanceof Array`, the live `Reflect.decorate` probe that reflect-metadata
// fills in after init). Array.from has no primordial: copying `arguments` goes
// through an index loop instead, because Array.from depends on the tamperable
// array iterator protocol.
const restrictedGlobals = ['Error', '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: ['NativeScript/runtime/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',
// Native globals resolved through the metadata interceptor at runtime:
interop: 'readonly',
NSUUID: 'readonly',
CGPoint: 'readonly',
CGRect: 'readonly',
CGSize: 'readonly',
UIEdgeInsets: 'readonly',
NSRange: 'readonly',
CFRunLoopGetCurrent: 'readonly',
CFRunLoopPerformBlock: 'readonly',
CFRunLoopWakeUp: 'readonly',
kCFRunLoopDefaultMode: 'readonly',
// Installed onto the global by inline-functions.js itself and
// referenced by bare name from its sibling decorators:
ObjCClass: 'readonly',
ObjCMethod: '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: ['NativeScript/runtime/js/primordials.js'],
rules: {
'no-restricted-properties': 'off',
'no-restricted-globals': 'off',
},
},
];