forked from TurboWarp/extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
157 lines (156 loc) · 5.36 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
// eslint-disable-next-line no-undef
module.exports = {
env: {
browser: true,
es2021: true
},
extends: 'eslint:recommended',
overrides: [
],
parserOptions: {
ecmaVersion: 'latest'
},
globals: {
Scratch: 'readonly'
},
rules: {
// Here is where we enforce rules to have somewhat consistent code style without being overbearing
'semi': [
'warn',
'always'
],
'brace-style': 'warn',
'key-spacing': 'warn',
'keyword-spacing': 'warn',
'new-parens': 'warn',
'no-trailing-spaces': [
'warn',
{
ignoreComments: true
}
],
'space-infix-ops': 'warn',
'no-tabs': 'warn',
// Allow blocks to accept unused `util` arguments
'no-unused-vars': 'off',
// Allow while (true) { }
'no-constant-condition': [
'error',
{
checkLoops: false
}
],
// Allow empty catch {} blocks
'no-empty': [
'error',
{
allowEmptyCatch: true
}
],
// Returning a value from a constructor() implies a mistake
'no-constructor-return': 'error',
// new Promise(async () => {}) implies a mistake
'no-async-promise-executor': 'warn',
// x === x implies a mistake
'no-self-compare': 'error',
// Using ${...} in a non-template-string implies a mistake
'no-template-curly-in-string': 'error',
// Loops that only iterate once imply a mistake
'no-unreachable-loop': 'error',
// Detect some untrusted code execution
'no-eval': 'error',
'no-implied-eval': 'error',
'no-new-func': 'error',
'no-script-url': 'error',
// Combinations of || and && are unreadable and may not do what you expect
'no-mixed-operators': [
'error',
{
groups: [
['&&', '||']
]
}
],
// Disallow async functions that don't need to be. This is important as a Promise and non-Promise return value
// significantly impacts the behavior of projects.
'require-await': 'error',
// Require each extension to use strict mode
'strict': ['error', 'function'],
// Disallow APIs that are replaced by Scratch.* APIs
// This is not comprehensive, but it should be enough to prevent the most common ways for these to be written.
'no-restricted-globals': [
'error',
{
name: 'vm',
message: 'Use Scratch.vm instead of the global vm object. You also can use const vm = Scratch.vm;'
}
],
'no-restricted-syntax': [
'error',
{
selector: 'CallExpression[callee.name=fetch]',
message: 'Use Scratch.fetch() instead of fetch()'
},
{
selector: 'CallExpression[callee.object.name=window][callee.property.name=fetch]',
message: 'Use Scratch.fetch() instead of window.fetch()'
},
{
selector: 'CallExpression[callee.name=open]',
message: 'Use Scratch.openWindow() instead of open()'
},
{
selector: 'CallExpression[callee.object.name=window][callee.property.name=open]',
message: 'Use Scratch.openWindow() instead of window.open()'
},
{
selector: 'AssignmentExpression[left.object.name=location][left.property.name=href]',
message: 'Use Scratch.redirect() instead of location.href = ...'
},
{
selector: 'AssignmentExpression[left.object.object.name=window][left.object.property.name=location][left.property.name=href]',
message: 'Use Scratch.redirect() instead of window.location.href = ...'
},
{
selector: 'AssignmentExpression[left.name=location]',
message: 'Use Scratch.redirect() instead of location = ...'
},
{
selector: 'AssignmentExpression[left.object.name=window][left.property.name=location]',
message: 'Use Scratch.redirect() instead of window.location = ...'
},
{
selector: 'CallExpression[callee.object.name=location][callee.property.name=assign]',
message: 'Use Scratch.redirect() instead of location.assign()'
},
{
selector: 'CallExpression[callee.object.object.name=window][callee.object.property.name=location][callee.property.name=assign]',
message: 'Use Scratch.redirect() instead of window.location.assign()'
},
{
selector: 'CallExpression[callee.object.name=location][callee.property.name=replace]',
message: 'Use Scratch.redirect() instead of location.replace()'
},
{
selector: 'CallExpression[callee.object.object.name=window][callee.object.property.name=location][callee.property.name=replace]',
message: 'Use Scratch.redirect() instead of window.location.replace()'
},
{
selector: 'NewExpression[callee.name=XMLHttpRequest]',
message: 'Use Scratch.fetch() instead of XMLHttpRequest'
},
{
selector: 'NewExpression[callee.name=WebSocket]',
message: 'Ensure that `await Scratch.canFetch(url)` is checked first, then add // eslint-disable-next-line no-restricted-syntax'
},
{
selector: 'NewExpression[callee.name=Image]',
message: 'Ensure that `await Scratch.canFetch(url)` is checked first, then add // eslint-disable-next-line no-restricted-syntax'
},
{
selector: 'NewExpression[callee.name=Audio]',
message: 'Ensure that `await Scratch.canFetch(url)` is checked first, then add // eslint-disable-next-line no-restricted-syntax'
}
]
}
};