forked from violentmonkey/violentmonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.js
196 lines (193 loc) · 6.02 KB
/
.eslintrc.js
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
const { readGlobalsFile } = require('./scripts/webpack-util');
const ovr = makeOverrides();
module.exports = {
root: true,
extends: [
require.resolve('@gera2ld/plaid/eslint'),
require.resolve('@gera2ld/plaid-common-vue/eslint/vue3-js'),
],
plugins: ['jest'],
rules: {
'prettier/prettier': 'off',
'no-use-before-define': ['error', {
'functions': false,
'classes': true,
'variables': true,
'allowNamedExports': true,
}],
// copied from airbnb-base, replaced 4 with 8
'object-curly-newline': ['error', {
ObjectExpression: { minProperties: 8, multiline: true, consistent: true },
ObjectPattern: { minProperties: 8, multiline: true, consistent: true },
ImportDeclaration: { minProperties: 8, multiline: true, consistent: true },
ExportDeclaration: { minProperties: 8, multiline: true, consistent: true },
}],
'semi': ['error'],
},
overrides: [{
// `browser` is a local variable since we remove the global `chrome` and `browser` in injected*
// to prevent exposing them to userscripts with `@inject-into content`
files: ['*'],
excludedFiles: [...ovr.FILES_INJECTED, ...ovr.FILES_SHARED],
globals: {
browser: false,
...ovr.GLOBALS_COMMON,
},
}, {
files: ovr.FILES_SHARED,
globals: ovr.GLOBALS_COMMON,
}, {
files: ovr.FILES_WEB,
globals: ovr.GLOBALS_WEB,
}, {
files: ovr.FILES_CONTENT,
globals: ovr.GLOBALS_CONTENT,
}, {
files: ovr.FILES_INJECTED,
excludedFiles: [...ovr.FILES_CONTENT, ...ovr.FILES_WEB],
// intersection of globals in CONTENT and WEB
globals: Object.keys(ovr.GLOBALS_CONTENT).reduce((res, key) => (
Object.assign(res, key in ovr.GLOBALS_WEB && { [key]: false })
), {}),
}, {
files: [...ovr.FILES_INJECTED, ...ovr.FILES_SHARED],
rules: ovr.INJECTED_RULES,
}, {
files: ovr.FILES_WEB,
rules: {
...ovr.INJECTED_RULES,
'no-restricted-syntax': [
...ovr.INJECTED_RULES['no-restricted-syntax'],
{
selector: '[regex], NewExpression[callee.name="RegExp"]',
message: 'RegExp internally depends on a *ton* of stuff that may be spoofed or broken',
// https://262.ecma-international.org/12.0/#sec-regexpexec
},
],
},
}, {
// build scripts
files: [
'*.js',
'scripts/*.js',
'scripts/*.mjs',
],
env: { node: true },
rules: {
'global-require': 0,
'import/newline-after-import': 0,
'import/no-extraneous-dependencies': 0, // spits errors in github action
'import/extensions': 0,
}
}, {
files: ['*.vue'],
rules: {
'vue/multi-word-component-names': 0,
},
}, {
files: ['test/**'],
env: {
'jest/globals': true,
},
}],
};
function makeOverrides() {
/* Note that `injected` uses several more `common` files indirectly, but we check just these
* two automatically because they are trivial by design and must always pass the check */
const GLOBALS_SHARED = getGlobals('*');
const GLOBALS_INJECTED = {
...getGlobals('injected'),
PAGE_MODE_HANDSHAKE: false,
VAULT_ID: false,
};
function getGlobals(path) {
const res = {};
const { ast } = readGlobalsFile(path, { ast: true });
ast.program.body.forEach(body => {
const { declarations } = body.declaration || body;
if (!declarations) return;
declarations.forEach(function processId({
id: {
left,
properties,
name = left && left.name,
},
}) {
if (name) {
// const NAME = whatever
// We consider `let` immutable too to avoid unintentional reassignment
res[name] = false;
} else if (properties) {
// const { NAME1, prototype: { NAME2: ALIAS2 } } = whatever
properties.forEach(({ value }) => processId({ id: value }));
}
});
});
return res;
}
return {
FILES_CONTENT: [
'src/injected/index.js',
'src/injected/content/**/*.js',
],
FILES_INJECTED: [
'src/injected/**/*.js',
],
FILES_SHARED: [
'src/common/browser.js',
'src/common/consts.js',
'src/common/safe-globals-shared.js',
],
FILES_WEB: [
'src/injected/web/**/*.js',
],
GLOBALS_INJECTED,
GLOBALS_SHARED,
GLOBALS_COMMON: {
...GLOBALS_SHARED,
...getGlobals('common'),
re: false, // transform-modern-regexp with useRe option
},
GLOBALS_CONTENT: {
INIT_FUNC_NAME: false,
...GLOBALS_SHARED,
...getGlobals('injected/content'),
...GLOBALS_INJECTED,
},
GLOBALS_WEB: {
...GLOBALS_SHARED,
...getGlobals('injected/web'),
...GLOBALS_INJECTED,
IS_FIREFOX: false, // passed as a parameter to VMInitInjection in webpack.conf.js
},
INJECTED_RULES: {
'no-restricted-imports': [
'error', {
patterns: ['*/common', '*/common/*'],
}
],
'no-restricted-syntax': [
'error', {
selector: 'ObjectExpression > ExperimentalSpreadProperty',
message: 'Object spread adds a polyfill in injected* even if unused by it',
}, {
selector: 'ArrayPattern',
message: 'Destructuring via Symbol.iterator may be spoofed/broken in an unsafe environment',
}, {
selector: ':matches(ArrayExpression, CallExpression) > SpreadElement',
message: 'Spreading via Symbol.iterator may be spoofed/broken in an unsafe environment',
}, {
selector: '[callee.object.name="Object"], MemberExpression[object.name="Object"]',
message: 'Using potentially spoofed methods in an unsafe environment',
// TODO: auto-generate the rule using GLOBALS
}, {
selector: `CallExpression[callee.name="defineProperty"]:not(${[
'[arguments.2.properties.0.key.name="__proto__"]',
':has(CallExpression[callee.name="nullObjFrom"])'
].join(',')})`,
message: 'Prototype of descriptor may be spoofed/broken in an unsafe environment',
}
],
},
};
}