-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy patheslint.config.mjs
381 lines (356 loc) · 11.9 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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
// @ts-check .ts config files are still experimental: https://github.com/eslint/eslint/discussions/17726
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
// @ts-expect-error no types available
import importPlugin from 'eslint-plugin-import'
import unicornPlugin from 'eslint-plugin-unicorn'
import jsdocPlugin from 'eslint-plugin-jsdoc'
import jasmine from 'eslint-plugin-jasmine'
import globals from 'globals'
// eslint-disable-next-line local-rules/disallow-protected-directory-import
import eslintLocalRules from './eslint-local-rules/index.js'
// eslint-disable-next-line import/no-default-export
export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.recommendedTypeChecked,
importPlugin.flatConfigs.recommended,
importPlugin.flatConfigs.typescript,
{
ignores: [
'packages/*/bundle',
'packages/*/cjs',
'packages/*/esm',
'developer-extension/dist',
'test/app/dist',
'sandbox',
'coverage',
'rum-events-format',
'.yarn',
],
},
{
plugins: {
unicorn: unicornPlugin,
'local-rules': { rules: eslintLocalRules },
jsdoc: jsdocPlugin,
jasmine,
},
languageOptions: {
parserOptions: {
project: [
'./tsconfig.json',
'./test/app/tsconfig.json',
'./test/e2e/tsconfig.json',
'./developer-extension/tsconfig.json',
'./performances/tsconfig.json',
],
sourceType: 'module',
// Without this option, typescript-eslint fails to lint .js files because we don't use
// `allowJs: true` in the TypeScript configuration. Same issue as
// https://github.com/typescript-eslint/typescript-eslint/issues/9749.
//
// Enabling `allowJs` would be a better solution, but right now it's not possible because of a
// pretty small reason with big implications: `webpack.base.js` includes
// `tsconfig-paths-webpack-plugin`, and this file includes Node.js types via a <reference>
// directive (see https://unpkg.com/browse/[email protected]/lib/plugin.d.ts).
//
// Because of this, Node.js types are included in the whole project, and because some of them
// are slightly different from the DOM/Browser types, some annoying typecheck errors are raised.
//
// So, ideally, we should:
// * add `allowJs: true` in the TypeScript configuration
// * have different tsconfig.json configurations for packages and scripts
// * when typechecking, run `tsc` multiple time with each configuration (like we do for the
// developer-extension)
// * then remove this option
disallowAutomaticSingleRunInference: true,
},
},
rules: {
'arrow-body-style': 'error',
camelcase: ['error', { properties: 'never', allow: ['_dd_temp_'] }],
curly: 'error',
eqeqeq: ['error', 'smart'],
'guard-for-in': 'error',
'id-denylist': [
'error',
'any',
'Number',
'number',
'String',
'string',
'Boolean',
'boolean',
'Undefined',
'undefined',
],
'id-match': 'error',
'no-bitwise': 'error',
'no-caller': 'error',
'no-else-return': 'error',
'no-eq-null': 'error',
'no-eval': 'error',
'no-extra-bind': 'error',
'no-inner-declarations': 'error',
'no-new-func': 'error',
'no-new-wrappers': 'error',
'no-return-await': 'error',
'no-sequences': 'error',
'no-template-curly-in-string': 'error',
'no-undef-init': 'error',
'no-unreachable': 'error',
'no-useless-concat': 'error',
'object-shorthand': 'error',
'one-var': ['error', 'never'],
'prefer-rest-params': 'off',
'prefer-template': 'error',
'prefer-object-spread': 'error',
quotes: ['error', 'single', { avoidEscape: true }],
radix: 'error',
'require-await': 'error',
'spaced-comment': [
'error',
'always',
{
line: {
markers: ['/'],
},
block: {
balanced: true,
},
},
],
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-expect-error': 'allow-with-description',
'ts-ignore': 'allow-with-description',
'ts-nocheck': 'allow-with-description',
'ts-check': 'allow-with-description',
},
],
'@typescript-eslint/no-restricted-types': [
'error',
{
types: {
/* eslint-disable id-denylist */
Object: { message: 'Avoid using the `Object` type. Did you mean `object`?' },
Boolean: { message: 'Avoid using the `Boolean` type. Did you mean `boolean`?' },
Number: { message: 'Avoid using the `Number` type. Did you mean `number`?' },
String: { message: 'Avoid using the `String` type. Did you mean `string`?' },
Symbol: { message: 'Avoid using the `Symbol` type. Did you mean `symbol`?' },
/* eslint-enable id-denylist */
},
},
],
'@typescript-eslint/consistent-type-imports': ['error'],
'@typescript-eslint/member-ordering': [
'error',
{
default: {
memberTypes: [
'signature',
'public-static-field',
'protected-static-field',
'private-static-field',
'public-decorated-field',
'public-instance-field',
'public-abstract-field',
'protected-decorated-field',
'protected-instance-field',
'protected-abstract-field',
'private-decorated-field',
'private-instance-field',
'public-constructor',
'protected-constructor',
'private-constructor',
'public-static-method',
'protected-static-method',
'private-static-method',
'public-decorated-method',
'public-instance-method',
'public-abstract-method',
'protected-decorated-method',
'protected-instance-method',
'protected-abstract-method',
'private-decorated-method',
'private-instance-method',
],
order: 'as-written',
},
},
],
'@typescript-eslint/no-empty-function': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unused-vars': ['error', { args: 'all', argsIgnorePattern: '^_', vars: 'all' }],
'@typescript-eslint/triple-slash-reference': ['error', { path: 'always', types: 'prefer-import', lib: 'always' }],
'import/no-cycle': 'error',
'import/no-default-export': 'error',
'import/no-duplicates': 'error',
'import/no-extraneous-dependencies': 'error',
'import/no-unresolved': [
'error',
{
commonjs: true,
ignore: [
// typescript-eslint package has no 'main' field, only 'exports', but
// eslint-plugin-import doesn't support it. See:
// * https://github.com/import-js/eslint-plugin-import/issues/3088#issuecomment-2425233952
// * https://github.com/browserify/resolve/issues/222
'typescript-eslint',
// The json-schema-to-typescript is built on demand (see scripts/cli build_json2type)
// and is not always available in the node_modules. Skip the import check.
'json-schema-to-typescript',
],
},
],
'import/no-useless-path-segments': 'error',
'import/order': 'error',
'jasmine/no-focused-tests': 'error',
'jsdoc/check-alignment': 'error',
'jsdoc/check-indentation': 'error',
'local-rules/disallow-test-import-export-from-src': 'error',
'local-rules/disallow-generic-utils': 'error',
'local-rules/disallow-protected-directory-import': [
'error',
{
ignore: [
// ignore packages index files so `[...]/test/*` can import from the `[...]/src/*`
'packages/*/src/index.ts',
],
},
],
'unicorn/filename-case': ['error', { case: 'camelCase' }],
'unicorn/no-empty-file': 'error',
},
},
{
files: ['**/*Event.types.ts'],
rules: {
'@typescript-eslint/naming-convention': [
'error',
{
leadingUnderscore: 'allow',
selector: 'property',
format: ['snake_case'],
},
],
},
},
{
files: ['scripts/**/*.spec.js', 'packages/*/scripts/**/*.spec.js'],
ignores: ['**/lib/**'],
rules: {
'unicorn/filename-case': ['error', { case: 'kebabCase' }],
},
},
{
files: ['scripts/**/*.js', 'packages/*/scripts/**/*.js'],
ignores: ['**/lib/**', '**/*.spec.js'],
rules: {
'unicorn/filename-case': ['error', { case: 'kebabCase' }],
'local-rules/secure-command-execution': 'error',
'local-rules/disallow-non-scripts': 'error',
},
},
{
// JS files. Allow weaker typings since TS can't infer types as accurately as TS files.
files: ['**/*.js'],
rules: {
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
},
},
{
files: ['packages/*/src/**/*.ts', 'developer-extension/src/**/*.{tsx,ts}'],
rules: {
'no-console': 'error',
},
},
{
files: ['packages/*/src/**/*.ts'],
ignores: ['**/*.spec.ts'],
rules: {
'local-rules/disallow-side-effects': 'error',
'local-rules/disallow-zone-js-patched-values': 'error',
'local-rules/disallow-url-constructor-patched-values': 'error',
'no-restricted-syntax': [
'error',
{
selector: 'ClassDeclaration',
message: 'Classes are not allowed. Use functions instead.',
},
{
selector: 'ArrayExpression > SpreadElement',
message: 'Array spread is not authorized. Please use .concat instead.',
},
{
selector: 'MemberExpression[object.name="Date"][property.name="now"]',
message: '`Date.now()` is not authorized. Please use `dateNow()` instead',
},
{
selector: 'TSEnumDeclaration:not([const=true])',
message: 'When possible, use `const enum` as it produces less code when transpiled.',
},
],
},
},
{
files: ['packages/**/*.ts'],
rules: {
'local-rules/disallow-spec-import': 'error',
},
},
{
files: ['packages/{rum,logs,rum-slim}/src/entries/*.ts'],
rules: {
'local-rules/disallow-enum-exports': 'error',
},
},
{
// Files executed by nodejs
files: [
'**/webpack.*.js',
'scripts/**/*.js',
'test/**/*.js',
'eslint-local-rules/**/*.js',
'eslint.config.mjs',
'packages/*/scripts/**/*.js',
],
languageOptions: {
globals: globals.node,
},
rules: {
'@typescript-eslint/no-require-imports': 'off',
},
},
{
files: ['test/e2e/**/*.ts'],
rules: {
// E2E codebase is importing @datadog/browser-* packages referenced by tsconfig.
'import/no-extraneous-dependencies': 'off',
},
},
{
files: ['packages/core/src/tools/**/*.ts'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['../**/boot/*', '../**/browser/*', '../**/domain/*', '../**/transport/*'],
message: 'tools components should not import from other directories',
},
],
},
],
},
}
)