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 384864d commit c0412e5
Show file tree
Hide file tree
Showing 30 changed files with 59 additions and 9 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 @@ -40,11 +40,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 @@ -72,6 +82,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 @@ -107,7 +126,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
2 changes: 1 addition & 1 deletion integration-tests/ci-visibility/run-workerpool.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const workerpool = require('workerpool')
const workerpool = require('workerpool') // eslint-disable-line n/no-extraneous-require
const pool = workerpool.pool({ workerType: 'process' })

function add (a, b) {
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
@@ -1 +1 @@
require('dd-trace/ci/cypress/support')
require('dd-trace/ci/cypress/support') // eslint-disable-line n/no-extraneous-require
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { expect } = require('chai')
const dependency = require('./dependency')

describe('subproject-test', () => {
Expand Down
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
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: 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
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'] }] */

const Module = require('module')
const { pathToFileURL } = require('url')
Expand Down
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: ['inspector/promises'] }] */

const { builtinModules } = require('node:module')

Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/src/profiling/exporters/event_serializer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
'use strict'
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['os.availableParallelism'] }] */

const os = require('os')
const perf = require('perf_hooks').performance
const version = require('../../../../../package.json').version
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/src/runtime_metrics.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: ['v8.GCProfiler'] }] */

// TODO: capture every second and flush every 10 seconds

Expand Down
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: ['fs.cp'] }] */

const os = require('os')
const path = require('path')
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/test/appsec/iast/resources/vm.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: ['vm.SourceTextModule'] }] */

const tracer = require('dd-trace')
tracer.init({
Expand Down
1 change: 1 addition & 0 deletions packages/dd-trace/test/appsec/index.next.plugin.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: ['fs.cpSync'] }] */

const { spawn, execSync } = require('child_process')
const { cpSync, mkdirSync, rmdirSync, unlinkSync } = require('fs')
Expand Down
2 changes: 2 additions & 0 deletions register.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint n/no-unsupported-features/node-builtins: ['error', { version: '>=20.6.0', allowExperimental: true }] */

const { register } = require('node:module')
const { pathToFileURL } = require('node:url')

Expand Down
2 changes: 2 additions & 0 deletions scripts/get-chrome-driver-download-url.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint n/no-unsupported-features/node-builtins: ['error', { version: '>=21.0.0', allowExperimental: true }] */

const URL = 'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json'

// Get chrome driver download URL from a given chrome version, provided via CHROME_VERSION env var
Expand Down
1 change: 1 addition & 0 deletions scripts/verify-ci-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'
/* eslint-disable no-console */
/* eslint n/no-unsupported-features/node-builtins: ['error', { version: '>=22.0.0', allowExperimental: true }] */

const fs = require('fs')
const path = require('path')
Expand Down

0 comments on commit c0412e5

Please sign in to comment.