Skip to content

Commit adbba87

Browse files
authored
Clean up ESLint config (#5214)
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 - Rename `package.json` script `lint-fix` to `lint:fix` - Delete unused `.rslintrc.json` files - Name all config groups (useful for debugging)
1 parent 66c13fc commit adbba87

File tree

15 files changed

+68
-130
lines changed

15 files changed

+68
-130
lines changed

benchmark/sirun/appsec-iast/insecure-bank.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const http = require('http')
2-
const app = require('/opt/insecure-bank-js/app')
2+
const app = require('/opt/insecure-bank-js/app') // eslint-disable-line import/no-absolute-path
33

44
const { port } = require('./common')
55

benchmark/sirun/appsec/insecure-bank.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const http = require('http')
2-
const app = require('/opt/insecure-bank-js/app')
2+
const app = require('/opt/insecure-bank-js/app') // eslint-disable-line import/no-absolute-path
33

44
const { port } = require('./common')
55

eslint.config.mjs

+46-41
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
import mocha from 'eslint-plugin-mocha'
2-
import n from 'eslint-plugin-n'
3-
import stylistic from '@stylistic/eslint-plugin-js'
4-
import globals from 'globals'
51
import path from 'node:path'
62
import { fileURLToPath } from 'node:url'
7-
import js from '@eslint/js'
3+
84
import { FlatCompat } from '@eslint/eslintrc'
5+
import js from '@eslint/js'
6+
import stylistic from '@stylistic/eslint-plugin-js'
7+
import mocha from 'eslint-plugin-mocha'
8+
import n from 'eslint-plugin-n'
9+
import globals from 'globals'
910

1011
const __filename = fileURLToPath(import.meta.url)
1112
const __dirname = path.dirname(__filename)
12-
const compat = new FlatCompat({
13-
baseDirectory: __dirname,
14-
recommendedConfig: js.configs.recommended,
15-
allConfig: js.configs.all
16-
})
13+
const compat = new FlatCompat({ baseDirectory: __dirname })
14+
15+
const TEST_FILES = [
16+
'packages/*/test/**/*.js',
17+
'packages/*/test/**/*.mjs',
18+
'integration-tests/**/*.js',
19+
'integration-tests/**/*.mjs',
20+
'**/*.spec.js'
21+
]
1722

1823
export default [
1924
{
@@ -31,9 +36,13 @@ export default [
3136
'packages/dd-trace/src/appsec/blocked_templates.js', // TODO Why is this ignored?
3237
'packages/dd-trace/src/payload-tagging/jsonpath-plus.js' // Vendored
3338
]
34-
}, ...compat.extends('eslint:recommended', 'standard', 'plugin:mocha/recommended'), {
39+
},
40+
{ name: '@eslint/js/recommnded', ...js.configs.recommended },
41+
...compat.extends('standard').map((config, i) => ({ name: config.name || `standard/${i + 1}`, ...config })),
42+
{
43+
name: 'dd-trace/defaults',
44+
3545
plugins: {
36-
mocha,
3746
n,
3847
'@stylistic/js': stylistic
3948
},
@@ -48,47 +57,43 @@ export default [
4857

4958
settings: {
5059
node: {
51-
version: '>=16.0.0'
60+
// Used by `eslint-plugin-n` to determine the minimum version of Node.js to support.
61+
// Normally setting this in the `package.json` engines field is enough, but when we have more than one active
62+
// major release line at the same time, we need to specify the lowest version here to ensure backporting will
63+
// not fail.
64+
version: '>=18.0.0'
5265
}
5366
},
5467

5568
rules: {
5669
'@stylistic/js/max-len': ['error', { code: 120, tabWidth: 2 }],
57-
'@stylistic/js/object-curly-newline': ['error', {
58-
multiline: true,
59-
consistent: true
60-
}],
70+
'@stylistic/js/object-curly-newline': ['error', { multiline: true, consistent: true }],
6171
'@stylistic/js/object-curly-spacing': ['error', 'always'],
62-
'import/no-absolute-path': 'off',
6372
'import/no-extraneous-dependencies': 'error',
64-
'n/no-callback-literal': 'off',
6573
'n/no-restricted-require': ['error', ['diagnostics_channel']],
6674
'no-console': 'error',
67-
'no-prototype-builtins': 'off',
68-
'no-unused-expressions': 'off',
69-
'no-var': 'error',
70-
'prefer-const': 'error',
71-
'standard/no-callback-literal': 'off'
75+
'no-prototype-builtins': 'off', // Override (turned on by @eslint/js/recommnded)
76+
'no-unused-expressions': 'off', // Override (turned on by standard)
77+
'no-var': 'error' // Override (set to warn in standard)
7278
}
7379
},
7480
{
75-
files: [
76-
'packages/*/test/**/*.js',
77-
'packages/*/test/**/*.mjs',
78-
'integration-tests/**/*.js',
79-
'integration-tests/**/*.mjs',
80-
'**/*.spec.js'
81-
],
81+
name: 'mocha/recommnded',
82+
...mocha.configs.flat.recommended,
83+
files: TEST_FILES
84+
},
85+
{
86+
name: 'dd-trace/tests/all',
87+
files: TEST_FILES,
8288
languageOptions: {
8389
globals: {
84-
...globals.mocha,
85-
sinon: false,
86-
expect: false,
87-
proxyquire: false,
88-
withVersions: false,
89-
withPeerService: false,
90-
withNamingSchema: false,
91-
withExports: false
90+
sinon: 'readonly',
91+
expect: 'readonly',
92+
proxyquire: 'readonly',
93+
withVersions: 'readonly',
94+
withPeerService: 'readonly',
95+
withNamingSchema: 'readonly',
96+
withExports: 'readonly'
9297
}
9398
},
9499
rules: {
@@ -101,11 +106,11 @@ export default [
101106
'mocha/no-sibling-hooks': 'off',
102107
'mocha/no-skipped-tests': 'off',
103108
'mocha/no-top-level-hooks': 'off',
104-
'n/handle-callback-err': 'off',
105-
'no-loss-of-precision': 'off'
109+
'n/handle-callback-err': 'off'
106110
}
107111
},
108112
{
113+
name: 'dd-trace/tests/integration',
109114
files: [
110115
'integration-tests/**/*.js',
111116
'integration-tests/**/*.mjs',

integration-tests/.eslintrc.json

-12
This file was deleted.

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ if (isMainThread) {
88
throw e
99
})
1010
} else {
11-
function dummyOperation (a) {
12-
return a + 'dummy operation with concat'
13-
}
14-
1511
dummyOperation('should not crash')
1612
}
13+
14+
function dummyOperation (a) {
15+
return a + 'dummy operation with concat'
16+
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"type:doc": "cd docs && yarn && yarn build",
1414
"type:test": "cd docs && yarn && yarn test",
1515
"lint": "node scripts/check_licenses.js && eslint . && yarn audit",
16-
"lint-fix": "node scripts/check_licenses.js && eslint . --fix && yarn audit",
16+
"lint:fix": "node scripts/check_licenses.js && eslint . --fix && yarn audit",
1717
"release:proposal": "node scripts/release/proposal",
1818
"services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
1919
"test": "SERVICES=* yarn services && mocha --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
@@ -117,7 +117,7 @@
117117
"devDependencies": {
118118
"@apollo/server": "^4.11.0",
119119
"@eslint/eslintrc": "^3.1.0",
120-
"@eslint/js": "^9.11.1",
120+
"@eslint/js": "^8.57.1",
121121
"@msgpack/msgpack": "^3.0.0-beta3",
122122
"@stylistic/eslint-plugin-js": "^2.8.0",
123123
"@types/node": "^16.0.0",

packages/.eslintrc.json

-21
This file was deleted.

packages/dd-trace/test/.eslintrc.json

-23
This file was deleted.

packages/dd-trace/test/debugger/devtools_client/state.spec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ describe('findScriptFromPartialPath', function () {
113113
})
114114
})
115115
})
116-
})
117116

118-
function testPath (path) {
119-
return function () {
120-
const result = state.findScriptFromPartialPath(path)
121-
expect(result).to.deep.equal([url, scriptId, undefined])
117+
function testPath (path) {
118+
return function () {
119+
const result = state.findScriptFromPartialPath(path)
120+
expect(result).to.deep.equal([url, scriptId, undefined])
121+
}
122122
}
123-
}
123+
})
124124
}
125125

126126
describe('multiple partial matches', function () {

packages/dd-trace/test/encode/0.5.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('encode 0.5', () => {
3535
example: 1
3636
},
3737
start: 123123123123123120,
38-
duration: 456456456456456456,
38+
duration: 4564564564564564,
3939
links: []
4040
}]
4141
})

packages/dd-trace/test/format.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('format', () => {
6060
_service: 'test'
6161
}),
6262
setTag: sinon.stub(),
63-
_startTime: 1500000000000.123456,
63+
_startTime: 1500000000000.123,
6464
_duration: 100
6565
}
6666

packages/dd-trace/test/lambda/fixtures/handler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const handler = async (_event, _context) => {
2323
const callbackHandler = (_event, _context, callback) => {
2424
const response = sampleResponse
2525

26-
callback('', response)
26+
callback('', response) // eslint-disable-line n/no-callback-literal
2727
}
2828

2929
const timeoutHandler = async (...args) => {

packages/dd-trace/test/llmobs/sdk/index.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ describe('sdk', () => {
560560
function myWorkflow (input, cb) {
561561
span = llmobs._active()
562562
setTimeout(() => {
563-
cb('output', 'ignore')
563+
cb('output', 'ignore') // eslint-disable-line n/no-callback-literal
564564
}, 1000)
565565
}
566566

packages/dd-trace/test/profiling/.eslintrc.json

-11
This file was deleted.

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,10 @@
609609
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f"
610610
integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==
611611

612-
"@eslint/js@^9.11.1":
613-
version "9.11.1"
614-
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-9.11.1.tgz#8bcb37436f9854b3d9a561440daf916acd940986"
615-
integrity sha512-/qu+TWz8WwPWc7/HcIJKi+c+MOm46GdVaSlTTQcaqaL53+GsoA6MxWp5PtTx48qbSP7ylM1Kn7nhvkugfJvRSA==
612+
"@eslint/js@^8.57.1":
613+
version "8.57.1"
614+
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.1.tgz#de633db3ec2ef6a3c89e2f19038063e8a122e2c2"
615+
integrity sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q==
616616

617617
"@graphql-tools/merge@^8.4.1":
618618
version "8.4.2"

0 commit comments

Comments
 (0)