-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy patheslint.config.mjs
More file actions
736 lines (720 loc) · 27.4 KB
/
eslint.config.mjs
File metadata and controls
736 lines (720 loc) · 27.4 KB
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
// TODO: once we've well iterated on this file (6 months+),
// we can plan to move it to its own package to reuse elsewhere.
// written on 2026-02-12
import { readFileSync } from 'fs'
import eslintPluginJs from '@eslint/js'
import eslintPluginStylistic from '@stylistic/eslint-plugin'
import eslintPluginCypress from 'eslint-plugin-cypress'
import eslintPluginImport from 'eslint-plugin-import'
import eslintPluginJSDoc from 'eslint-plugin-jsdoc'
import eslintPluginMocha from 'eslint-plugin-mocha'
import eslintPluginN from 'eslint-plugin-n'
import eslintPluginPromise from 'eslint-plugin-promise'
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
import globals from 'globals'
import eslintConfigNamesSync from './eslint-rules/eslint-config-names-sync.mjs'
import eslintEnvAliases from './eslint-rules/eslint-env-aliases.mjs'
import eslintLogPrintfStyle from './eslint-rules/eslint-log-printf-style.mjs'
import eslintProcessEnv from './eslint-rules/eslint-process-env.mjs'
import eslintRequireExportExists from './eslint-rules/eslint-require-export-exists.mjs'
import eslintSafeTypeOfObject from './eslint-rules/eslint-safe-typeof-object.mjs'
const { dependencies } = JSON.parse(readFileSync('./vendor/package.json', 'utf8'))
const SRC_FILES = [
'*.js',
'*.mjs',
'ext/**/*.js',
'ext/**/*.mjs',
'ci/**/*.js',
'ci/**/*.mjs',
'scripts/**/*.js',
'scripts/**/*.mjs',
'packages/*/*.js',
'packages/*/*.mjs',
'packages/*/src/**/*.js',
'packages/*/src/**/*.mjs',
]
const TEST_FILES = [
'packages/*/test/**/*.js',
'packages/*/test/**/*.mjs',
'integration-tests/**/*.js',
'integration-tests/**/*.mjs',
'**/*.spec.js',
]
const GLOBAL_RESTRICTED_REQUIRES = [
{
name: 'diagnostics_channel',
message: 'Please use `dc-polyfill` instead.',
},
{
name: 'get-port',
message: 'Please listen on port 0 instead.',
},
{
name: 'rimraf',
message: 'Please use `fs.rm(path, { recursive: true, force: true })` instead.',
},
{
name: 'koalas',
message: 'Please use nullish coalescing operator (??) instead.',
},
{
name: 'chai',
message: 'Please use `node:assert/strict` instead.',
},
{
name: 'tap',
message: 'Please use `mocha` instead.',
},
]
export default [
{
name: 'dd-trace/global-ignore',
ignores: [
'**/.bun', // Ignore autogenerated bun files
'**/coverage', // Just coverage reports.
'!**/integration-tests/coverage', // The integration-test coverage harness lives here, not a report.
'!**/integration-tests/coverage/**',
'**/dist', // Generated
'**/docs', // Any JS here is for presentation only.
'**/out', // Generated
'**/node_modules', // We don't own these.
'**/versions', // This is effectively a node_modules tree.
'**/acmeair-nodejs', // We don't own this.
'**/vendor', // Generally, we didn't author this code.
'**/.analysis', // Ignore apm-instrumentation-toolkit analysis results
'integration-tests/ci-visibility/test-management/test-suite-failed-to-run-parse.js', // Intentional syntax error
'integration-tests/code-origin/typescript.js', // Generated
'integration-tests/debugger/target-app/source-map-support/bundle.js', // Generated
'integration-tests/debugger/target-app/source-map-support/hello/world.js', // Generated
'integration-tests/debugger/target-app/source-map-support/minify.min.js', // Generated
'integration-tests/debugger/target-app/source-map-support/typescript.js', // Generated
'integration-tests/esbuild/out.js', // Generated
'integration-tests/esbuild/aws-sdk-out.js', // Generated
'packages/datadog-plugin-graphql/src/tools/index.js', // Inlined from apollo-graphql
'packages/datadog-plugin-graphql/src/tools/signature.js', // Inlined from apollo-graphql
'packages/datadog-plugin-graphql/src/tools/transforms.js', // Inlined from apollo-graphql
],
},
eslintPluginJs.configs.recommended,
eslintPluginJSDoc.configs['flat/recommended'],
{
// TODO: Move these rules to dd-trace/defaults or where they otherwise belong.
name: 'standard',
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
globals: {
...globals.es2022,
...globals.node,
document: 'readonly',
navigator: 'readonly',
window: 'readonly',
},
},
plugins: {
'@stylistic': eslintPluginStylistic,
jsdoc: eslintPluginJSDoc,
import: eslintPluginImport,
n: eslintPluginN,
promise: eslintPluginPromise,
},
rules: {
'@stylistic/array-bracket-spacing': ['error', 'never'],
'@stylistic/arrow-spacing': ['error', { before: true, after: true }],
'@stylistic/block-spacing': ['error', 'always'],
'@stylistic/comma-spacing': ['error', { before: false, after: true }],
'@stylistic/computed-property-spacing': ['error', 'never', { enforceForClassMembers: true }],
'@stylistic/dot-location': ['error', 'property'],
'@stylistic/eol-last': 'error',
'@stylistic/generator-star-spacing': ['error', { before: true, after: true }],
'@stylistic/key-spacing': ['error', { beforeColon: false, afterColon: true }],
'@stylistic/keyword-spacing': ['error', { before: true, after: true }],
'@stylistic/lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
'@stylistic/multiline-ternary': ['error', 'always-multiline'],
'@stylistic/new-parens': 'error',
'@stylistic/no-extra-parens': ['error', 'functions'],
'@stylistic/no-floating-decimal': 'error',
'@stylistic/no-mixed-spaces-and-tabs': 'error',
'@stylistic/no-multi-spaces': 'error',
'@stylistic/no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 0 }],
'@stylistic/no-tabs': 'error',
'@stylistic/no-trailing-spaces': 'error',
'@stylistic/no-whitespace-before-property': 'error',
'@stylistic/operator-linebreak': [
'error',
'after',
{ overrides: { '?': 'before', ':': 'before', '|>': 'before' } },
],
'@stylistic/padded-blocks': [
'error',
{ blocks: 'never', switches: 'never', classes: 'never' },
],
'@stylistic/quote-props': ['error', 'as-needed'],
'@stylistic/quotes': [
'error',
'single',
{ avoidEscape: true, allowTemplateLiterals: 'never' },
],
'@stylistic/rest-spread-spacing': ['error', 'never'],
'@stylistic/semi': ['error', 'never'],
'@stylistic/semi-spacing': ['error', { before: false, after: true }],
'@stylistic/space-before-blocks': ['error', 'always'],
'@stylistic/space-before-function-paren': ['error', 'always'],
'@stylistic/space-in-parens': ['error', 'never'],
'@stylistic/space-infix-ops': 'error',
'@stylistic/space-unary-ops': ['error', { words: true, nonwords: false }],
'@stylistic/spaced-comment': [
'error',
'always',
{
line: { markers: ['*package', '!', '/', ',', '='] },
block: {
balanced: true,
markers: ['*package', '!', ',', ':', '::', 'flow-include'],
exceptions: ['*'],
},
},
],
'@stylistic/template-curly-spacing': ['error', 'never'],
'@stylistic/template-tag-spacing': ['error', 'never'],
'@stylistic/wrap-iife': ['error', 'any', { functionPrototypeMethods: true }],
'@stylistic/yield-star-spacing': ['error', 'both'],
'accessor-pairs': ['error', { setWithoutGet: true, enforceForClassMembers: true }],
'array-callback-return': ['error', { allowImplicit: false, checkForEach: false }],
'brace-style': [ // TODO: Deprecated, use @stylistic/brace-style instead
'error',
'1tbs',
{ allowSingleLine: true },
],
camelcase: [
'error',
{
allow: ['^UNSAFE_'],
properties: 'never',
ignoreGlobals: true,
},
],
'comma-style': ['error', 'last'], // TODO: Deprecated, use @stylistic/comma-style instead
curly: ['error', 'multi-line'],
'default-case-last': 'error',
'dot-notation': ['error', { allowKeywords: true }],
eqeqeq: ['error', 'always', { null: 'ignore' }],
'func-call-spacing': ['error', 'never'], // TODO: Deprecated, use @stylistic/func-call-spacing instead
indent: [ // TODO: Deprecated, use @stylistic/indent instead
'error',
2,
{
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
MemberExpression: 1,
FunctionDeclaration: { parameters: 1, body: 1 },
FunctionExpression: { parameters: 1, body: 1 },
CallExpression: { arguments: 1 },
ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
ignoreComments: false,
ignoredNodes: [
'TemplateLiteral *',
'JSXElement',
'JSXElement > *',
'JSXAttribute',
'JSXIdentifier',
'JSXNamespacedName',
'JSXMemberExpression',
'JSXSpreadAttribute',
'JSXExpressionContainer',
'JSXOpeningElement',
'JSXClosingElement',
'JSXFragment',
'JSXOpeningFragment',
'JSXClosingFragment',
'JSXText',
'JSXEmptyExpression',
'JSXSpreadChild',
],
offsetTernaryExpressions: true,
},
],
'import/export': 'error',
'import/first': 'error',
'import/no-absolute-path': ['error', { esmodule: true, commonjs: true, amd: false }],
'import/no-cycle': 'error',
'import/no-duplicates': 'error',
'import/no-named-default': 'error',
'import/no-self-import': 'error',
'import/order': ['error', {
// `dd-trace` must be allowed first (and is often intentionally required before any other module).
// eslint-plugin-import defaults can exclude some import types (notably `builtin`) from `pathGroups`,
// which would make the `dd-trace` exception below a no-op. Make this explicit.
pathGroupsExcludedImportTypes: [],
pathGroups: [
{
pattern: 'dd-trace',
group: 'builtin',
position: 'before',
},
],
}],
'import/no-useless-path-segments': 'error',
'import/no-webpack-loader-syntax': 'error',
'jsdoc/check-param-names': ['error', { disableMissingParamChecks: true }],
'jsdoc/check-tag-names': ['error', { definedTags: ['datadog'] }],
// TODO: Enable the rules that we want to use.
// no-defaults: This should be activated, since the defaults will not be picked up in a description.
'jsdoc/no-defaults': 'off',
'jsdoc/no-undefined-types': 'off',
'jsdoc/reject-function-type': 'off',
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param-description': 'off', // Having a description is not crucial for now.
'jsdoc/require-param': 'off',
'jsdoc/require-property-description': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/require-returns-type': 'off',
'jsdoc/require-returns': 'off',
'jsdoc/tag-lines': 'off', // Alignment is not important for us.
'n/handle-callback-err': ['error', '^(err|error)$'],
'n/no-callback-literal': 'error',
'n/no-deprecated-api': 'error',
'n/no-exports-assign': 'error',
'n/no-new-require': 'error',
'n/no-path-concat': 'error',
'n/process-exit-as-throw': 'error',
'new-cap': ['error', { newIsCap: true, capIsNew: false, properties: true }],
'no-array-constructor': 'error',
'no-caller': 'error',
'no-constant-condition': ['error', { checkLoops: false }], // override config from @eslint/js/recommended
'no-empty': ['error', { allowEmptyCatch: true }], // override config from @eslint/js/recommended
'no-eval': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-implied-eval': 'error',
'no-iterator': 'error',
'no-labels': ['error', { allowLoop: false, allowSwitch: false }],
'no-lone-blocks': 'error',
'no-multi-str': 'error',
'no-new': 'error',
'no-new-func': 'error',
'no-new-wrappers': 'error',
'no-object-constructor': 'error',
'no-octal-escape': 'error',
'no-proto': 'error',
'no-redeclare': ['error', { builtinGlobals: false }], // override config from @eslint/js/recommended
'no-return-assign': ['error', 'except-parens'],
'no-self-compare': 'error',
'no-sequences': 'error',
'no-template-curly-in-string': 'error',
'no-throw-literal': 'error',
'no-undef-init': 'error',
'no-unmodified-loop-condition': 'error',
'no-unneeded-ternary': ['error', { defaultAssignment: false }],
'no-unreachable-loop': 'error',
'no-unused-vars': [ // override config from @eslint/js/recommended
'error',
{
args: 'none',
caughtErrors: 'none',
ignoreRestSiblings: true,
vars: 'all',
},
],
'no-use-before-define': ['error', { functions: false, classes: false, variables: false }],
'no-useless-call': 'error',
'no-useless-computed-key': 'error',
'no-useless-constructor': 'error',
'no-useless-rename': 'error',
'no-useless-return': 'error',
'no-void': 'error',
'object-property-newline': [ // TODO: Deprecated, use @stylistic/object-property-newline instead
'error',
{ allowMultiplePropertiesPerLine: true },
],
'object-shorthand': ['warn', 'properties'],
'one-var': ['error', { initialized: 'never' }],
'prefer-const': ['error', { destructuring: 'all' }],
'prefer-promise-reject-errors': 'error',
'prefer-regex-literals': ['error', { disallowRedundantWrapping: true }],
'promise/param-names': 'error',
'symbol-description': 'error',
'unicode-bom': ['error', 'never'],
'use-isnan': [ // override config from @eslint/js/recommended
'error',
{ enforceForSwitchCase: true, enforceForIndexOf: true },
],
yoda: ['error', 'never'],
},
},
{
...eslintPluginN.configs['flat/recommended'],
ignores: [
'integration-tests/debugger/target-app/re-evaluation/index.js',
'integration-tests/debugger/target-app/re-evaluation/unique-filename.js',
'packages/dd-trace/test/appsec/next/app-dir/**/*.js',
'packages/dd-trace/test/appsec/next/pages-dir/**/*.js',
'packages/datadog-plugin-next/test/app/**/*.js',
'packages/datadog-plugin-next/test/**/pages/**/*.js',
'packages/datadog-plugin-next/test/middleware.js',
'**/*.mjs', // TODO: This shouldn't be required, research why it is
],
},
{
name: 'dd-trace/defaults',
plugins: {
'@stylistic': eslintPluginStylistic,
'eslint-rules': {
rules: {
'eslint-process-env': eslintProcessEnv,
'eslint-env-aliases': eslintEnvAliases,
'eslint-config-names-sync': eslintConfigNamesSync,
'eslint-safe-typeof-object': eslintSafeTypeOfObject,
'eslint-log-printf-style': eslintLogPrintfStyle,
'eslint-require-export-exists': eslintRequireExportExists,
},
},
import: eslintPluginImport,
n: eslintPluginN,
},
languageOptions: {
globals: {
...globals.node,
},
ecmaVersion: 2022,
},
settings: {
node: {
// Used by `eslint-plugin-n` to determine the minimum version of Node.js to support.
// Normally setting this in the `package.json` engines field is enough, but when we have more than one active
// major release line at the same time, we need to specify the lowest version here to ensure backporting will
// not fail.
version: '>=18.0.0',
},
jsdoc: { mode: 'typescript' },
},
rules: {
'@stylistic/max-len': ['error', { code: 120, tabWidth: 2, ignoreUrls: true, ignoreRegExpLiterals: true }],
'@stylistic/object-curly-newline': ['error', { multiline: true, consistent: true }],
'@stylistic/object-curly-spacing': ['error', 'always'],
'@stylistic/comma-dangle': ['error', {
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
functions: 'only-multiline',
importAttributes: 'always-multiline',
dynamicImports: 'always-multiline',
}],
'eslint-rules/eslint-safe-typeof-object': 'error',
'eslint-rules/eslint-require-export-exists': 'error',
'import/no-extraneous-dependencies': 'error',
'n/hashbang': 'off', // TODO: Enable this rule once we have a plan to address it
'n/no-extraneous-require': ['error', {
allowModules: Object.keys(dependencies),
}],
'n/no-process-exit': 'off', // TODO: Enable this rule once we have a plan to address it
'n/no-restricted-require': ['error', GLOBAL_RESTRICTED_REQUIRES],
'n/no-unpublished-require': ['error', {
allowModules: Object.keys(dependencies),
}],
'n/no-unsupported-features/node-builtins': ['error', {
ignores: [
'Request',
'Response',
'async_hooks.createHook',
'async_hooks.executionAsyncId',
'async_hooks.executionAsyncResource',
'fetch',
'fs/promises.cp',
],
}],
'no-console': 'error',
'no-implicit-coercion': ['error', { boolean: true, number: true, string: true, allow: ['!!'] }],
'no-prototype-builtins': 'off', // Override (turned on by @eslint/js/recommended)
'no-useless-assignment': 'error',
'no-var': 'error',
'no-void': ['error', { allowAsStatement: true }],
'operator-assignment': 'error',
'prefer-exponentiation-operator': 'error',
'prefer-object-has-own': 'error',
'prefer-object-spread': 'error',
'require-await': 'error',
strict: 'error',
},
},
{
name: 'dd-trace/src/all',
files: SRC_FILES,
plugins: {
unicorn: eslintPluginUnicorn,
},
rules: {
'eslint-rules/eslint-process-env': 'error',
'eslint-rules/eslint-env-aliases': 'error',
'eslint-rules/eslint-log-printf-style': 'error',
'no-restricted-syntax': ['error', {
// Inline `.evaluate(<fn>)` callbacks (Playwright/Puppeteer) are serialized with
// `toString()` and run in chromium — coverage counters inside would ReferenceError.
selector:
"CallExpression[callee.property.name='evaluate']" +
":matches([arguments.0.type='ArrowFunctionExpression'], [arguments.0.type='FunctionExpression'])",
message:
'Move the inline `.evaluate(...)` callback into a `*-browser-scripts.js` file ' +
'(NYC-excluded in nyc.config.js) and import it here.',
}, {
// Static-analysis bundlers (esbuild, webpack, rollup) only see literals as require
// arguments; once any transform (e.g. NYC) wraps them, this shape breaks bundling.
selector: "CallExpression[callee.name='require'][arguments.0.type='ConditionalExpression']",
message: 'Use `cond ? require(\'a\') : require(\'b\')` instead of `require(cond ? \'a\' : \'b\')`.',
}],
'n/no-restricted-require': ['error', [
...GLOBAL_RESTRICTED_REQUIRES,
{
name: 'semver',
message: 'Please use `semifies` instead.',
},
]],
'no-await-in-loop': 'error',
'no-else-return': ['error', { allowElseIf: true }],
'no-unused-expressions': 'error',
// Too strict for now. Slowly migrate to this rule by using rest parameters.
// 'prefer-rest-params': 'error',
...eslintPluginUnicorn.configs.recommended.rules,
// Overriding recommended unicorn rules
'unicorn/catch-error-name': ['off', { name: 'err' }], // 166 errors
'unicorn/expiring-todo-comments': 'off',
'unicorn/explicit-length-check': 'off', // 68 errors
'unicorn/filename-case': ['off', { case: 'kebabCase' }], // 59 errors
'unicorn/prefer-at': 'off', // 17 errors | Difficult to fix
'unicorn/prefer-export-from': ['error', { ignoreUsedVariables: true }],
'unicorn/prevent-abbreviations': 'off', // too strict
// These rules require a newer Node.js version than we support
'unicorn/no-array-reverse': 'off', // Node.js 20
'unicorn/no-array-sort': 'off', // Node.js 20
// These rules could potentially evaluated again at a much later point
'unicorn/no-array-callback-reference': 'off',
'unicorn/no-for-loop': 'off', // Activate if this is resolved https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2664
'unicorn/no-nested-ternary': 'off', // Not really an issue in the code and the benefit is small
'unicorn/no-this-assignment': 'off', // This would need some further refactoring and the benefit is small
'unicorn/prefer-code-point': 'off', // Should be activated, but needs a refactor of some code
// The following rules should not be activated!
'unicorn/import-style': 'off', // Questionable benefit
'unicorn/no-array-reduce': 'off', // Questionable benefit
'unicorn/no-hex-escape': 'off', // Questionable benefit
'unicorn/no-new-array': 'off', // new Array is often used for performance reasons
'unicorn/no-null': 'off', // We do not control external APIs and it is hard to differentiate these
'unicorn/prefer-event-target': 'off', // Benefit only outside of Node.js
'unicorn/prefer-global-this': 'off', // Questionable benefit in Node.js alone
'unicorn/prefer-math-trunc': 'off', // Math.trunc is not a 1-to-1 replacement for most of our usage
'unicorn/prefer-module': 'off', // We use CJS
'unicorn/prefer-node-protocol': 'off', // May not be used due to guardrails
'unicorn/prefer-reflect-apply': 'off', // Questionable benefit and more than 500 matches
'unicorn/prefer-switch': 'off', // Questionable benefit
'unicorn/prefer-top-level-await': 'off', // Only useful when using ESM
'unicorn/switch-case-braces': 'off', // Questionable benefit
},
},
{
name: 'dd-trace/config-sync',
files: [
'eslint.config.mjs',
],
rules: {
'eslint-rules/eslint-config-names-sync': 'error',
},
},
{
name: 'dd-trace/scripts',
files: [
'scripts/**/*.js',
'scripts/**/*.mjs',
],
rules: {
'eslint-rules/eslint-process-env': 'off',
// Scripts are CLI/dev tooling where process.exit is acceptable.
'unicorn/no-process-exit': 'off',
},
},
{
name: 'dd-trace/defaults/v0.8-oldest',
plugins: {
n: eslintPluginN,
},
files: [
'init.js',
'packages/dd-trace/src/guardrails/**/*',
'version.js',
],
settings: {
node: {
version: '>=0.8.0',
},
},
rules: {
'@stylistic/comma-dangle': 'off', // Only supported in Node.js 0.10+
'eslint-rules/eslint-process-env': 'off', // Would require us to load a module outside the guardrails directory
'n/no-unsupported-features/es-builtins': ['error', {
// The following are false positives that are supported in Node.js 0.8.0
ignores: [
'JSON',
'JSON.stringify',
'parseInt',
'String',
],
}],
'n/no-unsupported-features/es-syntax': ['error', {
// The following are false positives that are supported in Node.js 0.8.0
ignores: [
'array-prototype-indexof',
'json',
],
}],
'no-var': 'off', // Only supported in Node.js 6+
'object-shorthand': 'off', // Only supported in Node.js 4+
'unicorn/prefer-includes': 'off', // Only supported in Node.js 6+
'unicorn/prefer-number-properties': 'off', // Only supported in Node.js 0.12+
'unicorn/prefer-optional-catch-binding': 'off', // Only supported in Node.js 10+
'unicorn/prefer-set-has': 'off', // Only supported in Node.js 0.12+
'unicorn/prefer-string-replace-all': 'off', // Only supported in Node.js 15+
},
},
{
name: 'dd-trace/defaults/v16-oldest',
plugins: {
n: eslintPluginN,
},
files: [
'packages/datadog-plugin-cypress/src/support.js',
],
settings: {
node: {
version: '>=16.0.0',
},
},
},
{
name: 'dd-trace/defaults/v18-latest',
plugins: {
n: eslintPluginN,
},
files: [
'benchmark/**/*',
'scripts/**/*',
...TEST_FILES,
],
settings: {
node: {
version: '>=18', // These files don't have to support the oldest v18 release
},
},
rules: {
'n/no-unsupported-features/node-builtins': ['error', {
allowExperimental: true,
ignores: [
'module.register',
],
}],
},
},
{
...eslintPluginCypress.configs.recommended,
files: [
'packages/datadog-plugin-cypress/src/support.js',
],
},
{
...eslintPluginMocha.configs.recommended,
files: TEST_FILES,
},
{
name: 'dd-trace/benchmarks',
files: [
'benchmark/**/*',
],
rules: {
'n/no-missing-require': 'off',
},
},
{
name: 'dd-trace/tests/all',
files: TEST_FILES,
plugins: {
mocha: eslintPluginMocha,
n: eslintPluginN,
},
rules: {
'mocha/consistent-spacing-between-blocks': 'off',
'mocha/max-top-level-suites': ['error', { limit: 1 }],
'mocha/no-mocha-arrows': 'off',
'mocha/no-setup-in-describe': 'off',
'mocha/no-sibling-hooks': 'off',
'mocha/no-top-level-hooks': 'off',
'n/handle-callback-err': 'off',
'n/no-extraneous-require': ['error', {
allowModules: [
...Object.keys(dependencies),
'mocha',
],
}],
'no-restricted-syntax': ['error', {
selector: "CallExpression:matches([callee.name='doesNotThrow'], [callee.property.name='doesNotThrow'])",
message: 'Do not use `assert.doesNotThrow()`. Execute the expression directly instead.',
}],
'n/no-missing-require': 'off',
'require-await': 'off',
},
},
{
name: 'dd-trace/test-optimization/relaxed',
files: [
'integration-tests/ci-visibility/**/*.js',
'integration-tests/ci-visibility/**/*.mjs',
'packages/datadog-plugin-jest/test/**/*.js',
'packages/datadog-plugin-mocha/test/**/*.js',
'packages/datadog-plugin-cucumber/test/**/*.js',
'packages/datadog-plugin-cypress/test/**/*.js',
'packages/datadog-plugin-playwright/test/**/*.js',
'packages/datadog-plugin-vitest/test/**/*.js',
],
plugins: {
mocha: eslintPluginMocha,
},
languageOptions: {
globals: {
afterAll: 'readonly',
beforeAll: 'readonly',
expect: 'readonly',
jest: 'readonly',
},
},
rules: {
'mocha/max-top-level-suites': 'off',
'mocha/no-pending-tests': 'off',
},
},
{
name: 'dd-trace/tests/integration-and-resources',
plugins: {
import: eslintPluginImport,
},
files: [
'integration-tests/**/*.js',
'integration-tests/**/*.mjs',
'packages/*/test/integration-test/**/*.js',
'packages/*/test/integration-test/**/*.mjs',
// TODO: Move the files in esm-test to integration-test
'packages/datadog-plugin-graphql/test/esm-test/**/*.mjs',
'packages/dd-trace/test/appsec/**/resources/**/*.js',
// TODO: Move the jest-test.js to integration-test
'packages/datadog-plugin-jest/test/jest-test.js',
],
rules: {
'import/no-extraneous-dependencies': 'off',
},
},
]