From b2946852949ddbf44adb459b51b03ea2a9804ca6 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Thu, 6 Feb 2025 00:18:10 +0100 Subject: [PATCH] Clean up ESLint config Overview over changes: - Allow the use of Node.js APIs in Node.js v18.0.0 and above - Remove disabled rules that were too agressive (replace with inline ignore comments or fix lint errors) - Scope mocha rules to only apply to test files - Use modern style of extending imported flat config files - Delete unused `.rslintrc.json` files - Name all config groups (useful for debugging) --- benchmark/sirun/appsec-iast/insecure-bank.js | 2 +- benchmark/sirun/appsec/insecure-bank.js | 2 +- eslint.config.mjs | 83 ++++++++++--------- integration-tests/.eslintrc.json | 12 --- integration-tests/appsec/esm-app/worker.mjs | 8 +- package.json | 2 +- packages/.eslintrc.json | 21 ----- packages/dd-trace/test/.eslintrc.json | 23 ----- .../debugger/devtools_client/state.spec.js | 12 +-- packages/dd-trace/test/encode/0.5.spec.js | 2 +- packages/dd-trace/test/format.spec.js | 2 +- .../dd-trace/test/lambda/fixtures/handler.js | 2 +- .../dd-trace/test/llmobs/sdk/index.spec.js | 2 +- .../dd-trace/test/profiling/.eslintrc.json | 11 --- yarn.lock | 8 +- 15 files changed, 63 insertions(+), 129 deletions(-) delete mode 100644 integration-tests/.eslintrc.json delete mode 100644 packages/.eslintrc.json delete mode 100644 packages/dd-trace/test/.eslintrc.json delete mode 100644 packages/dd-trace/test/profiling/.eslintrc.json diff --git a/benchmark/sirun/appsec-iast/insecure-bank.js b/benchmark/sirun/appsec-iast/insecure-bank.js index c8930910396..d07ab7c762f 100644 --- a/benchmark/sirun/appsec-iast/insecure-bank.js +++ b/benchmark/sirun/appsec-iast/insecure-bank.js @@ -1,5 +1,5 @@ const http = require('http') -const app = require('/opt/insecure-bank-js/app') +const app = require('/opt/insecure-bank-js/app') // eslint-disable-line import/no-absolute-path const { port } = require('./common') diff --git a/benchmark/sirun/appsec/insecure-bank.js b/benchmark/sirun/appsec/insecure-bank.js index c8930910396..d07ab7c762f 100644 --- a/benchmark/sirun/appsec/insecure-bank.js +++ b/benchmark/sirun/appsec/insecure-bank.js @@ -1,5 +1,5 @@ const http = require('http') -const app = require('/opt/insecure-bank-js/app') +const app = require('/opt/insecure-bank-js/app') // eslint-disable-line import/no-absolute-path const { port } = require('./common') diff --git a/eslint.config.mjs b/eslint.config.mjs index 8b83488c08e..eb5f40fcf85 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,19 +1,24 @@ -import mocha from 'eslint-plugin-mocha' -import n from 'eslint-plugin-n' -import stylistic from '@stylistic/eslint-plugin-js' -import globals from 'globals' import path from 'node:path' import { fileURLToPath } from 'node:url' -import js from '@eslint/js' + import { FlatCompat } from '@eslint/eslintrc' +import js from '@eslint/js' +import stylistic from '@stylistic/eslint-plugin-js' +import mocha from 'eslint-plugin-mocha' +import n from 'eslint-plugin-n' +import globals from 'globals' const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) -const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, - allConfig: js.configs.all -}) +const compat = new FlatCompat({ baseDirectory: __dirname }) + +const TEST_FILES = [ + 'packages/*/test/**/*.js', + 'packages/*/test/**/*.mjs', + 'integration-tests/**/*.js', + 'integration-tests/**/*.mjs', + '**/*.spec.js' +] export default [ { @@ -31,9 +36,13 @@ export default [ 'packages/dd-trace/src/appsec/blocked_templates.js', // TODO Why is this ignored? 'packages/dd-trace/src/payload-tagging/jsonpath-plus.js' // Vendored ] - }, ...compat.extends('eslint:recommended', 'standard', 'plugin:mocha/recommended'), { + }, + { name: '@eslint/js/recommnded', ...js.configs.recommended }, + ...compat.extends('standard').map((config, i) => ({ name: config.name || `standard/${i + 1}`, ...config })), + { + name: 'dd-trace/defaults', + plugins: { - mocha, n, '@stylistic/js': stylistic }, @@ -48,47 +57,39 @@ export default [ settings: { node: { - version: '>=16.0.0' + version: '>=18.0.0' } }, rules: { '@stylistic/js/max-len': ['error', { code: 120, tabWidth: 2 }], - '@stylistic/js/object-curly-newline': ['error', { - multiline: true, - consistent: true - }], + '@stylistic/js/object-curly-newline': ['error', { multiline: true, consistent: true }], '@stylistic/js/object-curly-spacing': ['error', 'always'], - 'import/no-absolute-path': 'off', 'import/no-extraneous-dependencies': 'error', - 'n/no-callback-literal': 'off', 'n/no-restricted-require': ['error', ['diagnostics_channel']], 'no-console': 'error', - 'no-prototype-builtins': 'off', - 'no-unused-expressions': 'off', - 'no-var': 'error', - 'prefer-const': 'error', - 'standard/no-callback-literal': 'off' + 'no-prototype-builtins': 'off', // Override (turned on by @eslint/js/recommnded) + 'no-unused-expressions': 'off', // Override (turned on by standard) + 'no-var': 'error' // Override (set to warn in standard) } }, { - files: [ - 'packages/*/test/**/*.js', - 'packages/*/test/**/*.mjs', - 'integration-tests/**/*.js', - 'integration-tests/**/*.mjs', - '**/*.spec.js' - ], + name: 'mocha/recommnded', + ...mocha.configs.flat.recommended, + files: TEST_FILES + }, + { + name: 'dd-trace/tests/all', + files: TEST_FILES, languageOptions: { globals: { - ...globals.mocha, - sinon: false, - expect: false, - proxyquire: false, - withVersions: false, - withPeerService: false, - withNamingSchema: false, - withExports: false + sinon: 'readonly', + expect: 'readonly', + proxyquire: 'readonly', + withVersions: 'readonly', + withPeerService: 'readonly', + withNamingSchema: 'readonly', + withExports: 'readonly' } }, rules: { @@ -101,11 +102,11 @@ export default [ 'mocha/no-sibling-hooks': 'off', 'mocha/no-skipped-tests': 'off', 'mocha/no-top-level-hooks': 'off', - 'n/handle-callback-err': 'off', - 'no-loss-of-precision': 'off' + 'n/handle-callback-err': 'off' } }, { + name: 'dd-trace/tests/integration', files: [ 'integration-tests/**/*.js', 'integration-tests/**/*.mjs', diff --git a/integration-tests/.eslintrc.json b/integration-tests/.eslintrc.json deleted file mode 100644 index b1afdd3cc9d..00000000000 --- a/integration-tests/.eslintrc.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": [ - "../.eslintrc.json" - ], - "env": { - "mocha": true - }, - "rules": { - "no-unused-expressions": 0, - "handle-callback-err": 0 - } -} diff --git a/integration-tests/appsec/esm-app/worker.mjs b/integration-tests/appsec/esm-app/worker.mjs index ea9558ce786..7f7672c4bc7 100644 --- a/integration-tests/appsec/esm-app/worker.mjs +++ b/integration-tests/appsec/esm-app/worker.mjs @@ -8,9 +8,9 @@ if (isMainThread) { throw e }) } else { - function dummyOperation (a) { - return a + 'dummy operation with concat' - } - dummyOperation('should not crash') } + +function dummyOperation (a) { + return a + 'dummy operation with concat' +} diff --git a/package.json b/package.json index 11073422b86..bc2cce01629 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,7 @@ "devDependencies": { "@apollo/server": "^4.11.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "^9.11.1", + "@eslint/js": "^8.57.1", "@msgpack/msgpack": "^3.0.0-beta3", "@stylistic/eslint-plugin-js": "^2.8.0", "@types/node": "^16.0.0", diff --git a/packages/.eslintrc.json b/packages/.eslintrc.json deleted file mode 100644 index 9ae4e0ef309..00000000000 --- a/packages/.eslintrc.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "extends": [ - "../.eslintrc.json" - ], - "env": { - "mocha": true - }, - "globals": { - "expect": true, - "sinon": true, - "proxyquire": true, - "withNamingSchema": true, - "withVersions": true, - "withExports": true, - "withPeerService": true - }, - "rules": { - "no-unused-expressions": 0, - "handle-callback-err": 0 - } -} diff --git a/packages/dd-trace/test/.eslintrc.json b/packages/dd-trace/test/.eslintrc.json deleted file mode 100644 index 3a9e197c393..00000000000 --- a/packages/dd-trace/test/.eslintrc.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "extends": [ - "../../../.eslintrc.json" - ], - "parserOptions": { - "ecmaVersion": 2022 - }, - "env": { - "mocha": true, - "es2022": true - }, - "globals": { - "expect": true, - "sinon": true, - "proxyquire": true, - "withVersions": true - }, - "rules": { - "no-unused-expressions": 0, - "handle-callback-err": 0, - "no-loss-of-precision": 0 - } -} diff --git a/packages/dd-trace/test/debugger/devtools_client/state.spec.js b/packages/dd-trace/test/debugger/devtools_client/state.spec.js index 59c971d0f7f..dced50d51e3 100644 --- a/packages/dd-trace/test/debugger/devtools_client/state.spec.js +++ b/packages/dd-trace/test/debugger/devtools_client/state.spec.js @@ -113,14 +113,14 @@ describe('findScriptFromPartialPath', function () { }) }) }) - }) - function testPath (path) { - return function () { - const result = state.findScriptFromPartialPath(path) - expect(result).to.deep.equal([url, scriptId, undefined]) + function testPath (path) { + return function () { + const result = state.findScriptFromPartialPath(path) + expect(result).to.deep.equal([url, scriptId, undefined]) + } } - } + }) } describe('multiple partial matches', function () { diff --git a/packages/dd-trace/test/encode/0.5.spec.js b/packages/dd-trace/test/encode/0.5.spec.js index 6c1fef4de2f..c28ca6fe492 100644 --- a/packages/dd-trace/test/encode/0.5.spec.js +++ b/packages/dd-trace/test/encode/0.5.spec.js @@ -35,7 +35,7 @@ describe('encode 0.5', () => { example: 1 }, start: 123123123123123120, - duration: 456456456456456456, + duration: 4564564564564564, links: [] }] }) diff --git a/packages/dd-trace/test/format.spec.js b/packages/dd-trace/test/format.spec.js index 846a02cd66a..66dbc090f4d 100644 --- a/packages/dd-trace/test/format.spec.js +++ b/packages/dd-trace/test/format.spec.js @@ -60,7 +60,7 @@ describe('format', () => { _service: 'test' }), setTag: sinon.stub(), - _startTime: 1500000000000.123456, + _startTime: 1500000000000.123, _duration: 100 } diff --git a/packages/dd-trace/test/lambda/fixtures/handler.js b/packages/dd-trace/test/lambda/fixtures/handler.js index 2541b0cd1cc..12cf0e8ad08 100644 --- a/packages/dd-trace/test/lambda/fixtures/handler.js +++ b/packages/dd-trace/test/lambda/fixtures/handler.js @@ -23,7 +23,7 @@ const handler = async (_event, _context) => { const callbackHandler = (_event, _context, callback) => { const response = sampleResponse - callback('', response) + callback('', response) // eslint-disable-line n/no-callback-literal } const timeoutHandler = async (...args) => { diff --git a/packages/dd-trace/test/llmobs/sdk/index.spec.js b/packages/dd-trace/test/llmobs/sdk/index.spec.js index e7cfb81a47d..0f6a09bf17e 100644 --- a/packages/dd-trace/test/llmobs/sdk/index.spec.js +++ b/packages/dd-trace/test/llmobs/sdk/index.spec.js @@ -560,7 +560,7 @@ describe('sdk', () => { function myWorkflow (input, cb) { span = llmobs._active() setTimeout(() => { - cb('output', 'ignore') + cb('output', 'ignore') // eslint-disable-line n/no-callback-literal }, 1000) } diff --git a/packages/dd-trace/test/profiling/.eslintrc.json b/packages/dd-trace/test/profiling/.eslintrc.json deleted file mode 100644 index 3f6d8f43424..00000000000 --- a/packages/dd-trace/test/profiling/.eslintrc.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": [ - "../.eslintrc.json" - ], - "env": { - "mocha" : true - }, - "rules": { - "no-unused-expressions": 0 - } -} diff --git a/yarn.lock b/yarn.lock index 3898b5233c9..bfd209d3df6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -609,10 +609,10 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f" integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g== -"@eslint/js@^9.11.1": - version "9.11.1" - resolved "https://registry.yarnpkg.com/@eslint/js/-/js-9.11.1.tgz#8bcb37436f9854b3d9a561440daf916acd940986" - integrity sha512-/qu+TWz8WwPWc7/HcIJKi+c+MOm46GdVaSlTTQcaqaL53+GsoA6MxWp5PtTx48qbSP7ylM1Kn7nhvkugfJvRSA== +"@eslint/js@^8.57.1": + version "8.57.1" + resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.1.tgz#de633db3ec2ef6a3c89e2f19038063e8a122e2c2" + integrity sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q== "@graphql-tools/merge@^8.4.1": version "8.4.2"