-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy patheslint.config.js
322 lines (290 loc) · 10.8 KB
/
eslint.config.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
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import jsdoc from 'eslint-plugin-jsdoc';
import config from 'eslint-config-mourner';
import tseslint from 'typescript-eslint';
import importPlugin from 'eslint-plugin-import';
import {globalIgnores} from 'eslint/config';
import {includeIgnoreFile} from '@eslint/compat';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const gitignorePath = path.resolve(__dirname, '.gitignore');
export default tseslint.config(
globalIgnores([
'./debug/**/*',
'./rollup/**/*',
'./src/style-spec/bin',
'./src/style-spec/dist',
'./test/build/typings/**/*',
'./test/build/transpilation/**/*',
]),
includeIgnoreFile(gitignorePath),
...config,
tseslint.configs.recommendedTypeChecked,
importPlugin.flatConfigs.recommended,
jsdoc.configs['flat/recommended'],
// Settings
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts'],
},
'import/resolver': {
node: true,
typescript: {
project: './tsconfig.json',
},
},
jsdoc: {
mode: 'typescript',
ignorePrivate: true,
preferredTypes: {
object: 'Object',
},
tagNamePreference: {
augments: 'extends',
method: 'method',
var: 'var',
}
},
}
},
// Default rules
{
rules: {
'no-loss-of-precision': 'off',
'no-use-before-define': 'off',
'implicit-arrow-linebreak': 'off',
'arrow-parens': 'off',
'arrow-body-style': 'off',
'no-confusing-arrow': 'off',
'no-control-regex': 'off',
'no-invalid-this': 'off',
'no-prototype-builtins': 'off',
'accessor-pairs': 'off',
'require-atomic-updates': 'off',
'array-bracket-spacing': 'off',
'consistent-return': 'off',
'global-require': 'off',
'import/no-commonjs': 'error',
'key-spacing': 'off',
'no-eq-null': 'off',
'no-lonely-if': 'off',
'no-new': 'off',
'no-warning-comments': 'error',
'dot-notation': 'off',
'no-else-return': 'off',
'no-lone-blocks': 'off',
'no-mixed-operators': ['error', {
groups: [['&', '|', '^', '~', '<<', '>>', '>>>'], ['&&', '||']],
}],
'object-curly-spacing': ['error', 'never'],
'prefer-arrow-callback': 'error',
'prefer-const': ['error', {
destructuring: 'all',
}],
'prefer-template': 'error',
'quotes': 'off',
'space-before-function-paren': 'off',
'template-curly-spacing': 'error',
'no-useless-escape': 'off',
'indent': ['error', 4, {
flatTernaryExpressions: true,
CallExpression: {arguments: 'off'},
FunctionDeclaration: {parameters: 'off'},
FunctionExpression: {parameters: 'off'},
}],
'no-multiple-empty-lines': ['error', {max: 1}],
'no-restricted-syntax': ['error',
{
selector: 'ObjectExpression > SpreadElement',
message: 'Spread syntax is not allowed for object assignments. Use Object.assign() or other methods instead.',
}, {
selector: 'AwaitExpression',
message: 'Async/await syntax is not allowed.',
}, {
selector: 'FunctionDeclaration[async=true]',
message: 'Async function declarations are not allowed.',
}, {
selector: 'FunctionExpression[async=true]',
message: 'Async function expressions are not allowed.',
}, {
selector: 'ArrowFunctionExpression[async=true]',
message: 'Async arrow functions are not allowed.',
}, {
selector: 'ClassProperty[value]',
message: 'ClassProperty values are not allowed.',
}, {
selector: 'LogicalExpression[operator=\'??\']',
message: 'Nullish coalescing is not allowed.',
}, {
selector: 'ChainExpression',
message: 'Optional chaining is now allowed.',
}
],
}
},
// TypeScript specific rules
{
rules: {
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-loss-of-precision': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/only-throw-error': 'off',
'@typescript-eslint/method-signature-style': 'error',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/restrict-template-expressions': ['off', {
allowNever: true,
}],
'@typescript-eslint/no-unnecessary-type-constraint': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', {
args: 'none',
caughtErrors: 'none',
ignoreRestSiblings: true,
}],
}
},
// Import plugin rules
{
rules: {
'import/named': 'off',
'import/namespace': 'off',
'import/default': 'off',
'import/no-named-as-default-member': 'off',
'import/no-unresolved': 'off',
'import/no-named-as-default': 'off',
'no-duplicate-imports': 'off',
'import/no-duplicates': 'error',
'import/order': ['error', {
groups: [[
'builtin',
'external',
'internal',
'unknown',
'parent',
'sibling',
'index',
'object',
], 'type'],
'newlines-between': 'always',
}],
'import/no-restricted-paths': ['error', {
zones: [{
target: './src/style-spec',
from: ['./src/!(style-spec)/**/*', './3d-style/**/*'],
}],
}],
'import/extensions': ['error', {
js: 'always',
json: 'always',
}],
},
},
// Stylistic rules
{
rules: {
'@stylistic/js/no-confusing-arrow': ['error', {onlyOneSimpleParam: true}],
'@stylistic/js/arrow-parens': 'off',
'@stylistic/js/indent': 'off',
'@stylistic/js/quotes': 'off',
}
},
// JSDoc specific rules
{
rules: {
'jsdoc/check-tag-names': ['warn', {
'definedTags': ['section', 'experimental', 'note'],
}],
// Disable JSDoc rules that are not relevant to public APIs.
'jsdoc/check-alignment': 'off',
'jsdoc/check-line-alignment': 'off',
'jsdoc/check-param-names': 'off',
'jsdoc/multiline-blocks': 'off',
'jsdoc/no-defaults': 'off',
'jsdoc/no-multi-asterisks': 'off',
'jsdoc/no-types': 'off',
'jsdoc/require-description-complete-sentence': 'off',
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param-description': 'off',
'jsdoc/require-param-type': 'off',
'jsdoc/require-param': 'off',
'jsdoc/require-returns-check': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/require-returns-type': 'off',
'jsdoc/require-returns': 'off',
'jsdoc/tag-lines': 'off',
}
},
// JSDoc specific rules for public APIs
{
files: [
'src/index.ts',
'src/ui/**',
'src/source/**',
'src/geo/lng_lat.ts',
'src/geo/mercator_coordinate.ts',
],
rules: {
'jsdoc/check-access': 'error',
'jsdoc/check-alignment': 'error',
'jsdoc/check-line-alignment': ['error'],
'jsdoc/check-param-names': 'error',
'jsdoc/check-property-names': 'error',
'jsdoc/check-types': 'error',
'jsdoc/multiline-blocks': 'error',
'jsdoc/no-multi-asterisks': ['error', {allowWhitespace: true}],
'jsdoc/require-description-complete-sentence': 'error',
'jsdoc/require-description': 'error',
'jsdoc/require-example': 'error',
'jsdoc/require-jsdoc': ['error', {publicOnly: true}],
'jsdoc/require-param-description': 'error',
'jsdoc/require-param-name': 'error',
'jsdoc/require-param-type': 'error',
'jsdoc/require-param': 'error',
'jsdoc/require-property-description': 'error',
'jsdoc/require-property-name': 'error',
'jsdoc/require-property-type': 'error',
'jsdoc/require-property': 'error',
'jsdoc/require-returns-check': 'error',
'jsdoc/require-returns-description': 'error',
'jsdoc/require-returns-type': 'error',
'jsdoc/require-returns': 'error',
'jsdoc/tag-lines': ['error', 'any', {startLines: 1}],
},
},
// Disable `no-restricted-syntax` for test/, build/, and config files
{
files: [
'test/**',
'build/**',
'rollup.*'
],
rules: {
'no-restricted-syntax': 'off',
}
},
// Disable type-aware linting for files that are not migrated to TypeScript
{
files: [
'./test/release/**/*',
'./test/integration/**/*',
'./test/build/style-spec.test.js',
'./test/build/browserify-test-fixture.js'
],
extends: [tseslint.configs.disableTypeChecked],
},
);