Skip to content

Commit b294685

Browse files
committed
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)
1 parent cde9361 commit b294685

File tree

15 files changed

+63
-129
lines changed

15 files changed

+63
-129
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 42 additions & 41 deletions
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,39 @@ export default [
4857

4958
settings: {
5059
node: {
51-
version: '>=16.0.0'
60+
version: '>=18.0.0'
5261
}
5362
},
5463

5564
rules: {
5665
'@stylistic/js/max-len': ['error', { code: 120, tabWidth: 2 }],
57-
'@stylistic/js/object-curly-newline': ['error', {
58-
multiline: true,
59-
consistent: true
60-
}],
66+
'@stylistic/js/object-curly-newline': ['error', { multiline: true, consistent: true }],
6167
'@stylistic/js/object-curly-spacing': ['error', 'always'],
62-
'import/no-absolute-path': 'off',
6368
'import/no-extraneous-dependencies': 'error',
64-
'n/no-callback-literal': 'off',
6569
'n/no-restricted-require': ['error', ['diagnostics_channel']],
6670
'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'
71+
'no-prototype-builtins': 'off', // Override (turned on by @eslint/js/recommnded)
72+
'no-unused-expressions': 'off', // Override (turned on by standard)
73+
'no-var': 'error' // Override (set to warn in standard)
7274
}
7375
},
7476
{
75-
files: [
76-
'packages/*/test/**/*.js',
77-
'packages/*/test/**/*.mjs',
78-
'integration-tests/**/*.js',
79-
'integration-tests/**/*.mjs',
80-
'**/*.spec.js'
81-
],
77+
name: 'mocha/recommnded',
78+
...mocha.configs.flat.recommended,
79+
files: TEST_FILES
80+
},
81+
{
82+
name: 'dd-trace/tests/all',
83+
files: TEST_FILES,
8284
languageOptions: {
8385
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
86+
sinon: 'readonly',
87+
expect: 'readonly',
88+
proxyquire: 'readonly',
89+
withVersions: 'readonly',
90+
withPeerService: 'readonly',
91+
withNamingSchema: 'readonly',
92+
withExports: 'readonly'
9293
}
9394
},
9495
rules: {
@@ -101,11 +102,11 @@ export default [
101102
'mocha/no-sibling-hooks': 'off',
102103
'mocha/no-skipped-tests': 'off',
103104
'mocha/no-top-level-hooks': 'off',
104-
'n/handle-callback-err': 'off',
105-
'no-loss-of-precision': 'off'
105+
'n/handle-callback-err': 'off'
106106
}
107107
},
108108
{
109+
name: 'dd-trace/tests/integration',
109110
files: [
110111
'integration-tests/**/*.js',
111112
'integration-tests/**/*.mjs',

integration-tests/.eslintrc.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 21 deletions
This file was deleted.

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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
})

0 commit comments

Comments
 (0)