Skip to content
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

Enable recommended rules for eslint-plugin-n #5216

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 @@ -73,6 +73,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]>
file,aws-lambda-nodejs-runtime-interface-client,Apache 2.0,Copyright 2019 Amazon.com Inc. or its affiliates. All Rights Reserved.
file,profile.proto,Apache license 2.0,Copyright 2016 Google Inc.
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

Choose a reason for hiding this comment

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

Will be fixed in #5274

module.exports = require('./packages/datadog-esbuild/index.js')
33 changes: 31 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,21 @@ export default [
},
{ name: '@eslint/js/recommnded', ...js.configs.recommended },
...compat.extends('standard').map((config, i) => ({ name: config.name || `standard/${i + 1}`, ...config })),
{
...n.configs['flat/recommended'],
ignores: [
'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',

plugins: {
n,
'@stylistic/js': stylistic
},

Expand Down Expand Up @@ -81,6 +91,15 @@ export default [
'@stylistic/js/object-curly-spacing': ['error', 'always'],
'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: [
'async_hooks.createHook',
'async_hooks.executionAsyncId',
'async_hooks.executionAsyncResource'
]
}],
'no-console': 'error',
'no-prototype-builtins': 'off', // Override (turned on by @eslint/js/recommnded)
'no-unused-expressions': 'off', // Override (turned on by standard)
Expand Down Expand Up @@ -108,6 +127,15 @@ export default [
]]
}
},
{
name: 'dd-trace/benchmarks',
files: [
'benchmark/**/*'
],
rules: {
'n/no-missing-require': 'off'
}
},
{
name: 'dd-trace/tests/all',
files: TEST_FILES,
Expand All @@ -132,7 +160,8 @@ export default [
'mocha/no-sibling-hooks': 'off',
'mocha/no-skipped-tests': 'off',
'mocha/no-top-level-hooks': 'off',
'n/handle-callback-err': 'off'
'n/handle-callback-err': 'off',
'n/no-missing-require': '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

Choose a reason for hiding this comment

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

Will be fixed in #5274

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

Choose a reason for hiding this comment

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

Will be fixed in #5274

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
1 change: 1 addition & 0 deletions integration-tests/appsec/multer.spec.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', { allowExperimental: true }] */

const { assert } = require('chai')
const path = require('path')
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,4 +1,3 @@
const { expect } = require('chai')
const dependency = require('./dependency')

describe('subproject-test', () => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"sinon-chai": "^3.7.0",
"tap": "^16.3.7",
"tiktoken": "^1.0.15",
"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.5.0"
}
}
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 shimmer = require('../../datadog-shimmer')
const { tracingChannel } = require('dc-polyfill')
Expand Down
1 change: 1 addition & 0 deletions packages/datadog-instrumentations/test/multer.spec.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: ['FormData'] }] */

const dc = require('dc-polyfill')
const axios = require('axios')
Expand Down
1 change: 1 addition & 0 deletions packages/datadog-plugin-fetch/test/index.spec.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 agent = require('../../dd-trace/test/plugins/agent')
const tags = require('../../../ext/tags')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
} = require('../../../../integration-tests/helpers')
const { assert } = require('chai')

// eslint-disable-next-line n/no-unsupported-features/node-builtins
const describe = globalThis.fetch ? globalThis.describe : globalThis.describe.skip

describe('esm', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['fetch'] }] */

import 'dd-trace/init.js'
import getPort from 'get-port'

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
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.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
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: ['fs.cp'] }] */

const os = require('os')
const path = require('path')
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/test/appsec/iast/resources/vm.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: ['vm.SourceTextModule'] }] */

const tracer = require('dd-trace')
tracer.init({
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/test/appsec/index.next.plugin.spec.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: ['fs.cpSync'] }] */

const { spawn, execSync } = require('child_process')
const { cpSync, mkdirSync, rmdirSync, unlinkSync } = require('fs')
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
2 changes: 2 additions & 0 deletions scripts/get-chrome-driver-download-url.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint n/no-unsupported-features/node-builtins: ['error', { version: '>=21.0.0', allowExperimental: true }] */

const URL = 'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json'

// Get chrome driver download URL from a given chrome version, provided via CHROME_VERSION env var
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', allowExperimental: true }] */

const fs = require('fs')
const path = require('path')
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5171,6 +5171,11 @@ workerpool@^6.5.1:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544"
integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==

workerpool@^9.2.0:
version "9.2.0"
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-9.2.0.tgz#f74427cbb61234708332ed8ab9cbf56dcb1c4371"
integrity sha512-PKZqBOCo6CYkVOwAxWxQaSF2Fvb5Iv2fCeTP7buyWI2GiynWr46NcXSgK/idoV6e60dgCBfgYc+Un3HMvmqP8w==

wrap-ansi@^6.2.0:
version "6.2.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz"
Expand Down
Loading