-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
eslint.config.mjs
308 lines (303 loc) · 8.02 KB
/
eslint.config.mjs
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import eslint from '@eslint/js';
import googleStyle from 'eslint-config-google';
import jsdoc from 'eslint-plugin-jsdoc';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tseslint from 'typescript-eslint';
// These rules are no longer supported, but the Google style package we depend
// on hasn't been updated in years to remove them, even though they have been
// removed from the repo. Manually delete them here to avoid breaking linting.
delete googleStyle.rules['valid-jsdoc'];
delete googleStyle.rules['require-jsdoc'];
const rules = {
'spaced-comment': [
'error',
'always',
{
'block': {
'balanced': true,
},
'exceptions': ['*'],
},
],
// Blockly uses prefixes for optional arguments and test-only functions.
'camelcase': [
'error',
{
'properties': 'never',
'allow': ['^opt_', '^_opt_', '^testOnly_'],
},
],
// Blockly uses capital letters for some non-constructor namespaces.
// Keep them for legacy reasons.
'new-cap': ['off'],
// Blockly uses objects as maps, but uses Object.create(null) to
// instantiate them.
'guard-for-in': ['off'],
};
/**
* Build shared settings for TS linting and add in the config differences.
* @param {object} root0 A configuration options struct.
* @param {!Array<string>} root0.files List of file globs to apply rules to.
* @param {string} root0.tsconfig Path to the tsconfig.json file to use.
* @returns {object} The override TS linting for given files and a given
* tsconfig.
*/
function buildTSOverride({files, tsconfig}) {
return {
files: files,
plugins: {
'@typescript-eslint': tseslint.plugin,
jsdoc,
},
languageOptions: {
parser: tseslint.parser,
'ecmaVersion': 2020,
'sourceType': 'module',
parserOptions: {
'project': tsconfig,
'tsconfigRootDir': '.',
},
globals: {
...globals.browser,
},
},
extends: [
...tseslint.configs.recommended,
jsdoc.configs['flat/recommended-typescript'],
eslintPluginPrettierRecommended,
],
rules: {
// TS rules
// Blockly uses namespaces to do declaration merging in some cases.
'@typescript-eslint/no-namespace': ['off'],
// Use the updated TypeScript-specific rule.
'no-invalid-this': ['off'],
'@typescript-eslint/no-invalid-this': ['error'],
'@typescript-eslint/no-unused-vars': [
'error',
{
'argsIgnorePattern': '^_',
'varsIgnorePattern': '^_',
},
],
// Temporarily disable. 23 problems.
'@typescript-eslint/no-explicit-any': ['off'],
// We use this pattern extensively for block (e.g. controls_if) interfaces.
'@typescript-eslint/no-empty-object-type': ['off'],
// params and returns docs are optional.
'jsdoc/require-param-description': ['off'],
'jsdoc/require-returns': ['off'],
// Disable for now (breaks on `this` which is not really a param).
'jsdoc/require-param': ['off'],
// Don't auto-add missing jsdoc. Only required on exported items.
'jsdoc/require-jsdoc': [
'warn',
{
'enableFixer': false,
'publicOnly': true,
},
],
'jsdoc/check-tag-names': [
'error',
{
'definedTags': [
'sealed',
'typeParam',
'remarks',
'define',
'nocollapse',
],
},
],
// Disabled due to not handling `this`. If re-enabled,
// checkDestructured option
// should be left as false.
'jsdoc/check-param-names': ['off', {'checkDestructured': false}],
// Allow any text in the license tag. Other checks are not relevant.
'jsdoc/check-values': ['off'],
// Ensure there is a blank line between the body and any @tags,
// as required by the tsdoc spec (see #6353).
'jsdoc/tag-lines': ['error', 'any', {'startLines': 1}],
},
};
}
export default [
{
// Note: there should be no other properties in this object
ignores: [
// Build artifacts
'msg/*',
'build/*',
'dist/*',
'typings/*',
'docs/*',
// Tests other than mocha unit tests
'tests/blocks/*',
'tests/themes/*',
'tests/compile/*',
'tests/jsunit/*',
'tests/generators/*',
'tests/mocha/webdriver.js',
'tests/screenshot/*',
'tests/test_runner.js',
'tests/workspace_svg/*',
// Demos, scripts, misc
'node_modules/*',
'generators/*',
'demos/*',
'appengine/*',
'externs/*',
'closure/*',
'scripts/gulpfiles/*',
'CHANGELOG.md',
'PULL_REQUEST_TEMPLATE.md',
],
},
eslint.configs.recommended,
jsdoc.configs['flat/recommended'],
googleStyle,
{
languageOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
settings: {
// Allowlist some JSDoc tag aliases we use.
'jsdoc': {
'tagNamePreference': {
'return': 'return',
'fileoverview': 'fileoverview',
'extends': 'extends',
'constructor': 'constructor',
},
},
},
rules,
},
{
files: [
'eslint.config.mjs',
'.prettierrc.js',
'gulpfile.js',
'scripts/helpers.js',
'tests/mocha/.mocharc.js',
'tests/migration/validate-renamings.mjs',
],
languageOptions: {
globals: {
...globals.node,
},
},
rules: {
'jsdoc/check-values': ['off'],
},
},
{
files: ['tests/**'],
languageOptions: {
globals: {
'Blockly': true,
'dartGenerator': true,
'javascriptGenerator': true,
'luaGenerator': true,
'phpGenerator': true,
'pythonGenerator': true,
},
},
rules: {
'jsdoc/check-values': ['off'],
'jsdoc/require-returns': ['off'],
'jsdoc/no-undefined-types': ['off'],
'jsdoc/valid-types': ['off'],
'jsdoc/check-types': ['off'],
'jsdoc/check-tag-names': ['warn', {'definedTags': ['record']}],
'jsdoc/tag-lines': ['off'],
'jsdoc/no-defaults': ['off'],
},
},
{
files: ['tests/browser/**'],
languageOptions: {
sourceType: 'module',
globals: {
'chai': false,
'sinon': false,
...globals.mocha,
...globals.browser,
...globals.node,
},
},
rules: {
// Allow uncommented helper functions in tests.
'jsdoc/require-jsdoc': ['off'],
'jsdoc/require-returns-type': ['off'],
'jsdoc/require-param-type': ['off'],
'no-invalid-this': ['off'],
},
},
{
files: ['tests/mocha/**'],
languageOptions: {
sourceType: 'module',
globals: {
'chai': false,
'sinon': false,
...globals.mocha,
...globals.browser,
},
},
rules: {
'no-unused-vars': ['off'],
// Allow uncommented helper functions in tests.
'jsdoc/require-jsdoc': ['off'],
'prefer-rest-params': ['off'],
'no-invalid-this': ['off'],
},
},
{
files: ['tests/node/**'],
languageOptions: {
globals: {
'console': true,
'require': true,
...globals.mocha,
...globals.node,
},
},
},
{
files: ['tests/playgrounds/**', 'tests/scripts/**'],
languageOptions: {
globals: {
...globals.browser,
},
},
},
{
files: ['scripts/**'],
languageOptions: {
globals: {
...globals.browser,
},
},
rules: {
'jsdoc/check-values': ['off'],
'jsdoc/require-returns': ['off'],
'jsdoc/tag-lines': ['off'],
},
},
...tseslint.config(
buildTSOverride({
files: ['**/*.ts', '**/*.tsx'],
tsconfig: './tsconfig.json',
}),
buildTSOverride({
files: ['tests/typescript/**/*.ts', 'tests/typescript/**/*.tsx'],
tsconfig: './tests/typescript/tsconfig.json',
}),
),
// Per the docs, this should be at the end because it disables rules that
// conflict with Prettier.
eslintPluginPrettierRecommended,
];