Skip to content

Commit

Permalink
Clean up ESLint config
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
watson committed Feb 6, 2025
1 parent cde9361 commit b294685
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 129 deletions.
2 changes: 1 addition & 1 deletion benchmark/sirun/appsec-iast/insecure-bank.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
2 changes: 1 addition & 1 deletion benchmark/sirun/appsec/insecure-bank.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
83 changes: 42 additions & 41 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -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 [
{
Expand All @@ -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
},
Expand All @@ -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: {
Expand All @@ -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',
Expand Down
12 changes: 0 additions & 12 deletions integration-tests/.eslintrc.json

This file was deleted.

8 changes: 4 additions & 4 deletions integration-tests/appsec/esm-app/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 0 additions & 21 deletions packages/.eslintrc.json

This file was deleted.

23 changes: 0 additions & 23 deletions packages/dd-trace/test/.eslintrc.json

This file was deleted.

12 changes: 6 additions & 6 deletions packages/dd-trace/test/debugger/devtools_client/state.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/encode/0.5.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('encode 0.5', () => {
example: 1
},
start: 123123123123123120,
duration: 456456456456456456,
duration: 4564564564564564,
links: []
}]
})
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('format', () => {
_service: 'test'
}),
setTag: sinon.stub(),
_startTime: 1500000000000.123456,
_startTime: 1500000000000.123,
_duration: 100
}

Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/lambda/fixtures/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/llmobs/sdk/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
11 changes: 0 additions & 11 deletions packages/dd-trace/test/profiling/.eslintrc.json

This file was deleted.

8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b294685

Please sign in to comment.