Skip to content

Commit

Permalink
Enable recommended rules for eslint-plugin-n
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Feb 6, 2025
1 parent affdfad commit a00cbf6
Show file tree
Hide file tree
Showing 64 changed files with 60 additions and 64 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') // eslint-disable-line import/no-absolute-path
const app = require('/opt/insecure-bank-js/app') // eslint-disable-line import/no-absolute-path, n/no-missing-require

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') // eslint-disable-line import/no-absolute-path
const app = require('/opt/insecure-bank-js/app') // eslint-disable-line import/no-absolute-path, n/no-missing-require

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

Expand Down
1 change: 1 addition & 0 deletions benchmark/sirun/plugin-bluebird/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ if (Number(process.env.USE_TRACER)) {
require('../../..').init()
}

// eslint-disable-next-line n/no-missing-require
const Promise = require('../../../versions/bluebird/node_modules/bluebird/js/release/bluebird')

const count = process.env.COUNT ? Number(process.env.COUNT) : 50000
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
module.exports = require('./packages/datadog-esbuild/index.js')
24 changes: 22 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,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 @@ -71,6 +81,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 @@ -106,7 +125,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
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
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
const sum = require('./dependency')
const { expect } = require('chai')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
const sum = require('./dependency')
const { expect } = require('chai')

Expand Down
1 change: 0 additions & 1 deletion integration-tests/ci-visibility/jest-flaky/flaky-fails.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
describe('test-flaky-test-retries', () => {
it('can retry failed tests', () => {
// eslint-disable-next-line
expect(1).toEqual(2)
})
})
2 changes: 0 additions & 2 deletions integration-tests/ci-visibility/jest-flaky/flaky-passes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ let counter = 0

describe('test-flaky-test-retries', () => {
it('can retry flaky tests', () => {
// eslint-disable-next-line
expect(++counter).toEqual(3)
})

it('will not retry passed tests', () => {
// eslint-disable-next-line
expect(3).toEqual(3)
})
})
1 change: 0 additions & 1 deletion integration-tests/ci-visibility/jestEnvironmentBadInit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line
require('dd-trace').init({
service: 'dd-trace-bad-init'
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
defaultCommandTimeout: 100,
e2e: {
setupNodeEvents (on, config) {
return require('dd-trace/ci/cypress/plugin')(on, config)
return require('dd-trace/ci/cypress/plugin')(on, config) // eslint-disable-line n/no-extraneous-require
},
specPattern: process.env.SPEC_PATTERN || 'cypress/e2e/**/*.cy.js'
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('dd-trace/ci/cypress/plugin')
module.exports = require('dd-trace/ci/cypress/plugin') // eslint-disable-line n/no-extraneous-require
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const dependency = require('./dependency')

describe('subproject-test', () => {
it('can run', () => {
// eslint-disable-next-line
expect(dependency(1, 2)).to.equal(3)
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
describe('test', () => {
it('can do snapshot', () => {
// eslint-disable-next-line
expect(1 + 2).toMatchSnapshot()
})
})
1 change: 0 additions & 1 deletion integration-tests/cypress-esm-config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import cypress from 'cypress'

async function runCypress () {
Expand Down
1 change: 0 additions & 1 deletion integration-tests/package-guardrails/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */

try {
const P = require('bluebird')
Expand Down
4 changes: 0 additions & 4 deletions loader-hook.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
// TODO(bengl): Not sure why `import/export` fails on this line, but it's just
// a passthrough to another module so it should be fine. Disabling for now.

// eslint-disable-next-line import/export
export * from 'import-in-the-middle/hook.mjs'
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ describe('Instrumentation', () => {
const store = 'store'

storage('legacy').run(store, () => {
// eslint-disable-next-line n/handle-callback-err
pool.acquire((err, resource) => {
pool.release(resource)
expect(storage('legacy').getStore()).to.equal(store)
Expand Down
3 changes: 0 additions & 3 deletions packages/datadog-instrumentations/test/mongoose.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ describe('mongoose instrumentations', () => {
Test.deleteOne({ type: 'test' }, (err) => {
expect(err).to.be.null

// eslint-disable-next-line n/handle-callback-err
Test.count({ type: 'test' }, (err, res) => {
expect(res).to.be.equal(2) // 3 -> delete 1 -> 2

Expand Down Expand Up @@ -259,7 +258,6 @@ describe('mongoose instrumentations', () => {
expect(item).not.to.be.null
expect(item.name).to.be.equal('test1')

// eslint-disable-next-line n/handle-callback-err
Test.count({ type: 'test' }, (err, res) => {
expect(res).to.be.equal(2) // 3 -> delete 1 -> 2

Expand Down Expand Up @@ -425,7 +423,6 @@ describe('mongoose instrumentations', () => {
$set: {
other: 'modified-other'
}
// eslint-disable-next-line n/handle-callback-err
}).then((err) => {
Test.find({ type: 'test' }).then((items) => {
expect(items.length).to.be.equal(3)
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: 0 additions & 1 deletion packages/datadog-instrumentations/test/url.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ names.forEach(name => {

describe('url.parse', () => {
it('should publish', () => {
// eslint-disable-next-line n/no-deprecated-api
const result = url.parse('https://www.datadoghq.com')

sinon.assert.calledOnceWithExactly(parseFinishedChannelCb, {
Expand Down
1 change: 0 additions & 1 deletion packages/datadog-plugin-aerospike/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ describe('Plugin', () => {
index: 'tags_idx',
datatype: aerospike.indexDataType.STRING
}
// eslint-disable-next-line n/handle-callback-err
client.createIndex(index, (error, job) => {
job.waitUntilDone((waitError) => {
const query = client.query(ns, 'demo')
Expand Down
1 change: 0 additions & 1 deletion packages/datadog-plugin-amqplib/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ describe('Plugin', () => {
channel.assertQueue('', {}, (err, ok) => {
if (err) return
channel.sendToQueue(ok.queue, Buffer.from('content'))
// eslint-disable-next-line n/handle-callback-err
channel.consume(ok.queue, () => {}, {}, (err, ok) => {})
})
},
Expand Down
1 change: 0 additions & 1 deletion packages/datadog-plugin-aws-sdk/test/stepfunctions.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @stylistic/js/max-len */
'use strict'

const semver = require('semver')
Expand Down
3 changes: 0 additions & 3 deletions packages/datadog-plugin-connect/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ describe('Plugin', () => {
const error = new Error('boom')

app.use((req, res) => { throw error })
// eslint-disable-next-line n/handle-callback-err
app.use((error, req, res, next) => {
res.statusCode = 500
res.end()
Expand Down Expand Up @@ -661,7 +660,6 @@ describe('Plugin', () => {
const error = new Error('boom')

app.use((req, res) => { throw error })
// eslint-disable-next-line n/handle-callback-err
app.use((error, req, res, next) => {
res.statusCode = 500
res.end()
Expand Down Expand Up @@ -803,7 +801,6 @@ describe('Plugin', () => {
const error = new Error('boom')

app.use((req, res) => { throw error })
// eslint-disable-next-line n/handle-callback-err
app.use((error, req, res, next) => {
res.statusCode = 500
res.end()
Expand Down
5 changes: 0 additions & 5 deletions packages/datadog-plugin-express/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ describe('Plugin', () => {
const app = express()

app.use(() => { throw new Error('boom') })
// eslint-disable-next-line n/handle-callback-err
app.use((err, req, res, next) => {
res.status(200).send()
})
Expand Down Expand Up @@ -334,7 +333,6 @@ describe('Plugin', () => {
next = _next
})
app.use(() => { throw error })
// eslint-disable-next-line n/handle-callback-err
app.use((err, req, res, next) => next())
app.get('/user/:id', (req, res) => {
res.status(200).send()
Expand Down Expand Up @@ -1155,7 +1153,6 @@ describe('Plugin', () => {
const error = new Error('boom')

app.use((req, res, next) => next(error))
// eslint-disable-next-line n/handle-callback-err
app.use((error, req, res, next) => res.status(500).send())

appListener = app.listen(0, 'localhost', () => {
Expand Down Expand Up @@ -1193,7 +1190,6 @@ describe('Plugin', () => {
const error = new Error('boom')

app.use((req, res) => { throw error })
// eslint-disable-next-line n/handle-callback-err
app.use((error, req, res, next) => res.status(500).send())

appListener = app.listen(0, 'localhost', () => {
Expand Down Expand Up @@ -1711,7 +1707,6 @@ describe('Plugin', () => {
const error = new Error('boom')

app.use((req, res) => { throw error })
// eslint-disable-next-line n/handle-callback-err
app.use((error, req, res, next) => res.status(500).send())

appListener = app.listen(0, 'localhost', () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/datadog-plugin-fastify/test/tracing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ describe('Plugin', () => {
it('should handle reply exceptions', done => {
let error

// eslint-disable-next-line n/handle-callback-err
app.setErrorHandler((error, request, reply) => {
reply.statusCode = 500
reply.send()
Expand Down Expand Up @@ -469,7 +468,6 @@ describe('Plugin', () => {
})

it('should ignore reply exceptions if the request succeeds', done => {
// eslint-disable-next-line n/handle-callback-err
app.setErrorHandler((error, request, reply) => {
reply.statusCode = 200
reply.send()
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
4 changes: 0 additions & 4 deletions packages/datadog-plugin-fs/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ describe('Plugin', () => {

it('should handle errors', (done) => {
const filename = path.join(__filename, Math.random().toString())
// eslint-disable-next-line n/handle-callback-err
fs.open(filename, 'r', (err) => {
expectOneSpan(agent, done, {
resource: 'open',
Expand Down Expand Up @@ -242,7 +241,6 @@ describe('Plugin', () => {

it('should handle errors', (done) => {
const filename = path.join(__filename, Math.random().toString())
// eslint-disable-next-line n/handle-callback-err
fs.promises.open(filename, 'r').catch((err) => {
expectOneSpan(agent, done, {
resource: 'promises.open',
Expand Down Expand Up @@ -1366,7 +1364,6 @@ describe('Plugin', () => {
'file.path': __filename
}
})
// eslint-disable-next-line n/handle-callback-err
// eslint-disable-next-line n/no-deprecated-api
fs.exists(__filename, () => {})
})
Expand Down Expand Up @@ -1962,7 +1959,6 @@ function testHandleErrors (fs, name, tested, args, agent) {
if (err) reject(err)
else resolve()
}
// eslint-disable-next-line n/handle-callback-err
tested(fs, args, null, err => {
expectOneSpan(agent, done, {
resource: name,
Expand Down
Loading

0 comments on commit a00cbf6

Please sign in to comment.