Skip to content

Commit e7cf286

Browse files
authored
Enable recommended rules for eslint-plugin-n (#5216)
Enables all recommended rules from the `eslint-plugin-n` ESLint plugin that can reasonably be enabled without too much work. The following rules have been disabled as they cause too many errors: - `n/hashbang` - `n/no-process-exit` - `n/no-missing-require` (only disabled in benchmarks and tests) All `eslint-plugin-n` rules are also disabled for `**/*.mjs` files as these for some reason resulting in parsing errors. Finally a select list of experimental Node.js APIs have been allowed in `n/no-unsupported-features/node-builtins`, so that we can use them without having to add ESLint comments all over the place: - `Response` - `async_hooks.createHook` - `async_hooks.executionAsyncId` - `async_hooks.executionAsyncResource` - `fetch` - `fs/promises.cp`
1 parent 9ff794c commit e7cf286

File tree

21 files changed

+96
-11
lines changed

21 files changed

+96
-11
lines changed

LICENSE-3rdparty.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen
6868
dev,sinon-chai,WTFPL and BSD-2-Clause,Copyright 2004 Sam Hocevar 2012–2017 Domenic Denicola
6969
dev,tap,ISC,Copyright 2011-2022 Isaac Z. Schlueter and Contributors
7070
dev,tiktoken,MIT,Copyright (c) 2022 OpenAI, Shantanu Jain
71+
dev,workerpool,Apache license 2.0,Copyright (C) 2014-2024 Jos de Jong wjosdejong@gmail.com
7172
dev,yaml,ISC,Copyright Eemeli Aro <eemeli@gmail.com>
7273
dev,yarn-deduplicate,Apache license 2.0,Copyright [yyyy] [name of copyright owner]
7374
file,aws-lambda-nodejs-runtime-interface-client,Apache 2.0,Copyright 2019 Amazon.com Inc. or its affiliates. All Rights Reserved.

esbuild.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
'use strict'
22

3+
// TODO: It shouldn't be necessary to disable n/no-unpublished-require - Research
4+
// eslint-disable-next-line n/no-unpublished-require
35
module.exports = require('./packages/datadog-esbuild/index.js')

eslint.config.mjs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,19 @@ export default [
286286
yoda: ['error', 'never']
287287
}
288288
},
289+
{
290+
...eslintPluginN.configs['flat/recommended'],
291+
ignores: [
292+
'integration-tests/debugger/target-app/re-evaluation/index.js',
293+
'integration-tests/debugger/target-app/re-evaluation/unique-filename.js',
294+
'packages/dd-trace/test/appsec/next/app-dir/**/*.js',
295+
'packages/dd-trace/test/appsec/next/pages-dir/**/*.js',
296+
'packages/datadog-plugin-next/test/app/**/*.js',
297+
'packages/datadog-plugin-next/test/**/pages/**/*.js',
298+
'packages/datadog-plugin-next/test/middleware.js',
299+
'**/*.mjs' // TODO: This shoudln't be required, research why it is
300+
]
301+
},
289302
{
290303
name: 'dd-trace/defaults',
291304

@@ -328,6 +341,18 @@ export default [
328341
}],
329342
'import/no-extraneous-dependencies': 'error',
330343
'n/no-restricted-require': ['error', ['diagnostics_channel']],
344+
'n/hashbang': 'off', // TODO: Enable this rule once we have a plan to address it
345+
'n/no-process-exit': 'off', // TODO: Enable this rule once we have a plan to address it
346+
'n/no-unsupported-features/node-builtins': ['error', {
347+
ignores: [
348+
'Response',
349+
'async_hooks.createHook',
350+
'async_hooks.executionAsyncId',
351+
'async_hooks.executionAsyncResource',
352+
'fetch',
353+
'fs/promises.cp'
354+
]
355+
}],
331356
'no-console': 'error',
332357
'no-prototype-builtins': 'off', // Override (turned on by @eslint/js/recommended)
333358
'no-var': 'error',
@@ -421,6 +446,26 @@ export default [
421446
...eslintPluginMocha.configs.flat.recommended,
422447
files: TEST_FILES
423448
},
449+
{
450+
name: 'dd-trace/benchmarks',
451+
files: [
452+
'benchmark/**/*'
453+
],
454+
rules: {
455+
'n/no-missing-require': 'off'
456+
}
457+
},
458+
{
459+
name: 'dd-trace/scripts',
460+
files: [
461+
'scripts/**/*'
462+
],
463+
rules: {
464+
'n/no-unsupported-features/node-builtins': ['error', {
465+
allowExperimental: true
466+
}]
467+
}
468+
},
424469
{
425470
name: 'dd-trace/tests/all',
426471
files: TEST_FILES,
@@ -447,6 +492,10 @@ export default [
447492
'mocha/no-skipped-tests': 'off',
448493
'mocha/no-top-level-hooks': 'off',
449494
'n/handle-callback-err': 'off',
495+
'n/no-missing-require': 'off',
496+
'n/no-unsupported-features/node-builtins': ['error', {
497+
allowExperimental: true
498+
}],
450499
'require-await': 'off'
451500
}
452501
},

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
'use strict'
22

3+
// TODO: It shouldn't be necessary to disable n/no-unpublished-require - Research
4+
// eslint-disable-next-line n/no-unpublished-require
35
module.exports = require('./packages/dd-trace')

init.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
/* eslint-disable no-var */
44

5+
// TODO: It shouldn't be necessary to disable n/no-unpublished-require - Research
6+
// eslint-disable-next-line n/no-unpublished-require
57
var guard = require('./packages/dd-trace/src/guardrails')
68

79
module.exports = guard(function () {

initialize.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* hook will always be active for ESM support.
1111
*/
1212

13+
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['module.register'] }] */
14+
1315
import { isMainThread } from 'worker_threads'
1416

1517
import * as Module from 'node:module'

integration-tests/appsec/esm-app/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict'
2+
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['module.register'] }] */
23

34
import childProcess from 'node:child_process'
45
import express from 'express'

integration-tests/ci-visibility/subproject/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"name": "subproject",
33
"private": true,
44
"version": "1.0.0",
5-
"description": "app within repo"
5+
"description": "app within repo",
6+
"dependencies": {
7+
"dd-trace": "file:../../.."
8+
}
69
}

integration-tests/ci-visibility/subproject/subproject-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: It shouldn't be necessary to disable n/no-extraneous-require - Research
2+
// eslint-disable-next-line n/no-extraneous-require
13
const { expect } = require('chai')
24
const dependency = require('./dependency')
35

integration-tests/esbuild/index.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
const chproc = require('child_process')
88
const path = require('path')
99
const fs = require('fs')
10+
// TODO: It shouldn't be necessary to disable n/no-extraneous-require - Research
11+
// eslint-disable-next-line n/no-extraneous-require
1012
const { assert } = require('chai')
1113

1214
const TEST_DIR = path.join(__dirname, '.')

0 commit comments

Comments
 (0)