Skip to content

Enable recommended rules for eslint-plugin-n #5216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen
dev,sinon-chai,WTFPL and BSD-2-Clause,Copyright 2004 Sam Hocevar 2012–2017 Domenic Denicola
dev,tap,ISC,Copyright 2011-2022 Isaac Z. Schlueter and Contributors
dev,tiktoken,MIT,Copyright (c) 2022 OpenAI, Shantanu Jain
dev,workerpool,Apache license 2.0,Copyright (C) 2014-2024 Jos de Jong [email protected]
dev,yaml,ISC,Copyright Eemeli Aro <[email protected]>
dev,yarn-deduplicate,Apache license 2.0,Copyright [yyyy] [name of copyright owner]
file,aws-lambda-nodejs-runtime-interface-client,Apache 2.0,Copyright 2019 Amazon.com Inc. or its affiliates. All Rights Reserved.
Expand Down
2 changes: 2 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

// TODO: It shouldn't be necessary to disable n/no-unpublished-require - Research
// eslint-disable-next-line n/no-unpublished-require
Comment on lines +3 to +4
Copy link
Collaborator Author

@watson watson Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be fixed in #5320

module.exports = require('./packages/datadog-esbuild/index.js')
49 changes: 49 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,19 @@ export default [
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 shoudln't be required, research why it is
]
},
{
name: 'dd-trace/defaults',

Expand Down Expand Up @@ -328,6 +341,18 @@ export default [
}],
'import/no-extraneous-dependencies': 'error',
'n/no-restricted-require': ['error', ['diagnostics_channel']],
'n/hashbang': 'off', // TODO: Enable this rule once we have a plan to address it
'n/no-process-exit': 'off', // TODO: Enable this rule once we have a plan to address it
'n/no-unsupported-features/node-builtins': ['error', {
ignores: [
'Response',
'async_hooks.createHook',
'async_hooks.executionAsyncId',
'async_hooks.executionAsyncResource',
'fetch',
'fs/promises.cp'
]
}],
'no-console': 'error',
'no-prototype-builtins': 'off', // Override (turned on by @eslint/js/recommended)
'no-var': 'error',
Expand Down Expand Up @@ -421,6 +446,26 @@ export default [
...eslintPluginMocha.configs.flat.recommended,
files: TEST_FILES
},
{
name: 'dd-trace/benchmarks',
files: [
'benchmark/**/*'
],
rules: {
'n/no-missing-require': 'off'
}
},
{
name: 'dd-trace/scripts',
files: [
'scripts/**/*'
],
rules: {
'n/no-unsupported-features/node-builtins': ['error', {
allowExperimental: true
}]
}
},
{
name: 'dd-trace/tests/all',
files: TEST_FILES,
Expand All @@ -447,6 +492,10 @@ export default [
'mocha/no-skipped-tests': 'off',
'mocha/no-top-level-hooks': 'off',
'n/handle-callback-err': 'off',
'n/no-missing-require': 'off',
'n/no-unsupported-features/node-builtins': ['error', {
allowExperimental: true
}],
'require-await': 'off'
}
},
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

// TODO: It shouldn't be necessary to disable n/no-unpublished-require - Research
// eslint-disable-next-line n/no-unpublished-require
Comment on lines +3 to +4
Copy link
Collaborator Author

@watson watson Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be fixed in #5320

module.exports = require('./packages/dd-trace')
2 changes: 2 additions & 0 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

/* eslint-disable no-var */

// TODO: It shouldn't be necessary to disable n/no-unpublished-require - Research
// eslint-disable-next-line n/no-unpublished-require
Comment on lines +5 to +6
Copy link
Collaborator Author

@watson watson Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be fixed in #5320

var guard = require('./packages/dd-trace/src/guardrails')

module.exports = guard(function () {
Expand Down
2 changes: 2 additions & 0 deletions initialize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* hook will always be active for ESM support.
*/

/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['module.register'] }] */

import { isMainThread } from 'worker_threads'

import * as Module from 'node:module'
Expand Down
1 change: 1 addition & 0 deletions integration-tests/appsec/esm-app/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['module.register'] }] */

import childProcess from 'node:child_process'
import express from 'express'
Expand Down
5 changes: 4 additions & 1 deletion integration-tests/ci-visibility/subproject/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"name": "subproject",
"private": true,
"version": "1.0.0",
"description": "app within repo"
"description": "app within repo",
"dependencies": {
"dd-trace": "file:../../.."
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO: It shouldn't be necessary to disable n/no-extraneous-require - Research
// eslint-disable-next-line n/no-extraneous-require
const { expect } = require('chai')
const dependency = require('./dependency')

Expand Down
2 changes: 2 additions & 0 deletions integration-tests/esbuild/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
const chproc = require('child_process')
const path = require('path')
const fs = require('fs')
// TODO: It shouldn't be necessary to disable n/no-extraneous-require - Research
// eslint-disable-next-line n/no-extraneous-require
const { assert } = require('chai')

const TEST_DIR = path.join(__dirname, '.')
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"sinon-chai": "^3.7.0",
"tap": "^16.3.10",
"tiktoken": "^1.0.21",
"workerpool": "^9.2.0",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our code worked previously because workerpool just happened to be a sub-dependency of another one of our dependencies. That sub-dependency was v6.5.1 though, so some breaking changes has been introduced between that and this. For an overview of them, see https://github.com/josdejong/workerpool/blob/master/HISTORY.md

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juan-fernandez The workerpool module is used by CI Visibility in integration-tests/ci-visibility/run-workerpool.js, so you should probably take a look to check that everything is ok. However, I assume it is, since the integration tests are passing after the upgrade.

"yaml": "^2.8.0",
"yarn-deduplicate": "^6.0.2"
}
Expand Down
1 change: 1 addition & 0 deletions packages/datadog-instrumentations/src/fetch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['fetch', 'Request'] }] */

const { isInServerlessEnvironment } = require('../../dd-trace/src/serverless')

Expand Down
6 changes: 3 additions & 3 deletions packages/datadog-plugin-openai/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Plugin', () => {

after(() => {
if (semver.satisfies(realVersion, '>=5.0.0') && NODE_MAJOR < 20) {
global.File = globalFile
global.File = globalFile // eslint-disable-line n/no-unsupported-features/node-builtins
}

return agent.close({ ritmReset: false })
Expand All @@ -62,8 +62,8 @@ describe('Plugin', () => {
* Error: `File` is not defined as a global, which is required for file uploads.
* Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`.
*/
globalFile = global.File
global.File = require('node:buffer').File
globalFile = global.File // eslint-disable-line n/no-unsupported-features/node-builtins
global.File = require('node:buffer').File // eslint-disable-line n/no-unsupported-features/node-builtins
}

if (semver.satisfies(realVersion, '>=4.0.0')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['module.register'] }] */

const Module = require('module')
const { pathToFileURL } = require('url')
Expand Down
16 changes: 12 additions & 4 deletions packages/dd-trace/src/debugger/devtools_client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ const SUPPORT_ARRAY_BUFFER_RESIZE = NODE_MAJOR >= 20
const oneSecondNs = 1_000_000_000n
let globalSnapshotSamplingRateWindowStart = 0n
let snapshotsSampledWithinTheLastSecond = 0
// TODO: Is a limit of 256 snapshots ever going to be a problem?
const snapshotProbeIndexBuffer = new ArrayBuffer(1, { maxByteLength: 256 })
// TODO: Is a limit of 256 probes ever going to be a problem?

// TODO: Change to const once we drop support for Node.js 18
let snapshotProbeIndex = new Uint8Array(snapshotProbeIndexBuffer)
let snapshotProbeIndexBuffer, snapshotProbeIndex

if (SUPPORT_ARRAY_BUFFER_RESIZE) {
// TODO: Is a limit of 256 snapshots ever going to be a problem?
// eslint-disable-next-line n/no-unsupported-features/es-syntax
snapshotProbeIndexBuffer = new ArrayBuffer(1, { maxByteLength: 256 })
// TODO: Is a limit of 256 probes ever going to be a problem?
snapshotProbeIndex = new Uint8Array(snapshotProbeIndexBuffer)
} else {
snapshotProbeIndex = new Uint8Array(1)
}

// WARNING: The code above the line `await session.post('Debugger.resume')` is highly optimized. Please edit with care!
session.on('Debugger.paused', async ({ params }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['inspector/promises'] }] */

const { builtinModules } = require('node:module')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
'use strict'
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['os.availableParallelism'] }] */

const os = require('os')
const perf = require('perf_hooks').performance
const version = require('../../../../../package.json').version
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/src/runtime_metrics/runtime_metrics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['v8.GCProfiler'] }] */

// TODO: capture every second and flush every 10 seconds

Expand Down
2 changes: 2 additions & 0 deletions register.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint n/no-unsupported-features/node-builtins: ['error', { version: '>=20.6.0', allowExperimental: true }] */

const { register } = require('node:module')
const { pathToFileURL } = require('node:url')

Expand Down
1 change: 1 addition & 0 deletions scripts/verify-ci-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'
/* eslint-disable no-console */
/* eslint n/no-unsupported-features/node-builtins: ['error', { version: '>=22.0.0' }] */

const fs = require('fs')
const path = require('path')
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5023,9 +5023,9 @@ word-wrap@^1.2.5:
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==

workerpool@^9.2.0:
version "9.3.2"
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-9.3.2.tgz#4c045a8b437ae1bc70c646af11929a8b4d238656"
integrity sha512-Xz4Nm9c+LiBHhDR5bDLnNzmj6+5F+cyEAWPMkbs2awq/dYazR/efelZzUAjB/y3kNHL+uzkHvxVVpaOfGCPV7A==
version "9.3.3"
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-9.3.3.tgz#e75281fe62e851afb21cdeef8fa85f6a62ec3583"
integrity sha512-slxCaKbYjEdFT/o2rH9xS1hf4uRDch1w7Uo+apxhZ+sf/1d9e0ZVkn42kPNGP2dgjIx6YFvSevj0zHvbWe2jdw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
Expand Down