Skip to content

Commit d376439

Browse files
authored
ESLint: Scope certain files to other Node.js versions than v18.0.0 (#6030)
Not all of our files have Node.js 18.0.0 as the target version.
1 parent 9453dcf commit d376439

File tree

8 files changed

+90
-36
lines changed

8 files changed

+90
-36
lines changed

eslint.config.mjs

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ export default [
5151
'integration-tests/esbuild/aws-sdk-out.js', // Generated
5252
'packages/datadog-plugin-graphql/src/tools/index.js', // Inlined from apollo-graphql
5353
'packages/datadog-plugin-graphql/src/tools/signature.js', // Inlined from apollo-graphql
54-
'packages/datadog-plugin-graphql/src/tools/transforms.js', // Inlined from apollo-graphql
55-
'packages/dd-trace/src/guardrails/**/*' // Guardrails contain very old JS
54+
'packages/datadog-plugin-graphql/src/tools/transforms.js' // Inlined from apollo-graphql
5655
]
5756
},
5857
{ name: '@eslint/js/recommended', ...eslintPluginJs.configs.recommended },
@@ -301,21 +300,17 @@ export default [
301300
},
302301
{
303302
name: 'dd-trace/defaults',
304-
305303
plugins: {
306304
'@stylistic': eslintPluginStylistic,
307305
import: eslintPluginImport,
308306
n: eslintPluginN
309307
},
310-
311308
languageOptions: {
312309
globals: {
313310
...globals.node
314311
},
315-
316312
ecmaVersion: 2022
317313
},
318-
319314
settings: {
320315
node: {
321316
// Used by `eslint-plugin-n` to determine the minimum version of Node.js to support.
@@ -325,7 +320,6 @@ export default [
325320
version: '>=18.0.0'
326321
}
327322
},
328-
329323
rules: {
330324
'@stylistic/max-len': ['error', { code: 120, tabWidth: 2, ignoreUrls: true, ignoreRegExpLiterals: true }],
331325
'@stylistic/object-curly-newline': ['error', { multiline: true, consistent: true }],
@@ -436,6 +430,81 @@ export default [
436430
'unicorn/switch-case-braces': 'off', // Questionable benefit
437431
}
438432
},
433+
{
434+
name: 'dd-trace/defaults/v0.8-oldest',
435+
plugins: {
436+
n: eslintPluginN
437+
},
438+
files: [
439+
'init.js',
440+
'packages/dd-trace/src/guardrails/**/*',
441+
'version.js'
442+
],
443+
settings: {
444+
node: {
445+
version: '>=0.8.0'
446+
}
447+
},
448+
rules: {
449+
'eslint-rules/eslint-process-env': 'off', // Would require us to load a module outside the guardrails directory
450+
'n/no-unsupported-features/es-builtins': ['error', {
451+
// The following are false positives that are supported in Node.js 0.8.0
452+
ignores: [
453+
'JSON',
454+
'JSON.stringify',
455+
'parseInt',
456+
'String'
457+
]
458+
}],
459+
'n/no-unsupported-features/es-syntax': ['error', {
460+
// The following are false positives that are supported in Node.js 0.8.0
461+
ignores: [
462+
'array-prototype-indexof',
463+
'json'
464+
]
465+
}],
466+
'no-var': 'off', // Only supported in Node.js 6+
467+
'object-shorthand': 'off', // Only supported in Node.js 4+
468+
'unicorn/prefer-includes': 'off', // Only supported in Node.js 6+
469+
'unicorn/prefer-number-properties': 'off', // Only supported in Node.js 0.12+
470+
'unicorn/prefer-optional-catch-binding': 'off', // Only supported in Node.js 10+
471+
'unicorn/prefer-set-has': 'off', // Only supported in Node.js 0.12+
472+
'unicorn/prefer-string-replace-all': 'off' // Only supported in Node.js 15+
473+
}
474+
},
475+
{
476+
name: 'dd-trace/defaults/v16-oldest',
477+
plugins: {
478+
n: eslintPluginN
479+
},
480+
files: [
481+
'packages/datadog-plugin-cypress/src/support.js'
482+
],
483+
settings: {
484+
node: {
485+
version: '>=16.0.0'
486+
}
487+
}
488+
},
489+
{
490+
name: 'dd-trace/defaults/v18-latest',
491+
plugins: {
492+
n: eslintPluginN
493+
},
494+
files: [
495+
'benchmark/**/*',
496+
'scripts/**/*',
497+
...TEST_FILES
498+
],
499+
settings: {
500+
node: {
501+
version: '>=18' // These files don't have to support the oldest v18 release
502+
}
503+
},
504+
rules: {
505+
'n/no-unsupported-features/node-builtins': ['error', { allowExperimental: true }]
506+
}
507+
},
439508
{
440509
...eslintPluginCypress.configs.recommended,
441510
files: [
@@ -462,9 +531,7 @@ export default [
462531
'scripts/**/*'
463532
],
464533
rules: {
465-
'n/no-unsupported-features/node-builtins': ['error', {
466-
allowExperimental: true
467-
}]
534+
'n/no-unsupported-features/node-builtins': ['error', { allowExperimental: true }]
468535
}
469536
},
470537
{
@@ -494,9 +561,7 @@ export default [
494561
'mocha/no-top-level-hooks': 'off',
495562
'n/handle-callback-err': 'off',
496563
'n/no-missing-require': 'off',
497-
'n/no-unsupported-features/node-builtins': ['error', {
498-
allowExperimental: true
499-
}],
564+
'n/no-unsupported-features/node-builtins': ['error', { allowExperimental: true }],
500565
'require-await': 'off'
501566
}
502567
},

init.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
/* eslint-disable no-var */
4-
53
// TODO: It shouldn't be necessary to disable n/no-unpublished-require - Research
64
// eslint-disable-next-line n/no-unpublished-require
75
var guard = require('./packages/dd-trace/src/guardrails')

packages/datadog-plugin-cypress/src/support.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function isNewTest (test) {
3030
}
3131

3232
function getTestProperties (testName) {
33-
// We neeed to do it in this way because of compatibility with older versions as '?' is not supported in older
34-
// versions of Cypress
33+
// TODO: Use optional chaining when we drop support for older Cypress versions, which will happen when dd-trace@5 is
34+
// EoL. Until then, this files needs to support Node.js 16.
3535
const properties = testManagementTests[testName] && testManagementTests[testName].properties || {}
3636

3737
const { attempt_to_fix: isAttemptToFix, disabled: isDisabled, quarantined: isQuarantined } = properties

packages/dd-trace/src/guardrails/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
/* eslint-disable no-var */
4-
53
var path = require('path')
64
var Module = require('module')
75
var isTrue = require('./util').isTrue
@@ -26,9 +24,11 @@ function guard (fn) {
2624
var resolvedInApp
2725
var entrypoint = process.argv[1]
2826
try {
27+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
2928
resolvedInApp = Module.createRequire(entrypoint).resolve('dd-trace')
3029
} catch (e) {
3130
// Ignore. If we can't resolve the module, we assume it's not in the app.
31+
// TODO: There's also the possibility that this version of Node.js doesn't have Module.createRequire (pre v12.2.0)
3232
}
3333
if (resolvedInApp) {
3434
var ourselves = path.normalize(path.join(__dirname, '..', '..', '..', '..', 'index.js'))
@@ -54,8 +54,7 @@ function guard (fn) {
5454
}
5555

5656
if (!clobberBailout && (!initBailout || forced)) {
57-
// Ensure the instrumentation source is set for the current process and potential
58-
// child processes.
57+
// Ensure the instrumentation source is set for the current process and potential child processes.
5958
var result = fn()
6059
telemetry('complete', ['injection_forced:' + (forced && initBailout ? 'true' : 'false')])
6160
log.info('Application instrumentation bootstrapping complete')

packages/dd-trace/src/guardrails/log.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
/* eslint-disable no-var */
43
/* eslint-disable no-console */
54

65
var isTrue = require('./util').isTrue
@@ -23,7 +22,8 @@ var logLevel = isTrue(DD_TRACE_DEBUG)
2322
: logLevels.off
2423

2524
var log = {
26-
debug: logLevel <= 20 ? console.debug.bind(console) : function () {},
25+
/* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['console.debug'] }] */
26+
debug: logLevel <= 20 ? (console.debug || console.log).bind(console) : function () {},
2727
info: logLevel <= 30 ? console.info.bind(console) : function () {},
2828
warn: logLevel <= 40 ? console.warn.bind(console) : function () {},
2929
error: logLevel <= 50 ? console.error.bind(console) : function () {}

packages/dd-trace/src/guardrails/telemetry.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
'use strict'
22

3-
/* eslint-disable no-var */
4-
/* eslint-disable object-shorthand */
5-
63
var fs = require('fs')
74
var spawn = require('child_process').spawn
85
var tracerVersion = require('../../../../package.json').version
@@ -11,12 +8,12 @@ var log = require('./log')
118
module.exports = sendTelemetry
129

1310
if (!process.env.DD_INJECTION_ENABLED) {
14-
module.exports = function () {}
11+
module.exports = function noop () {}
1512
}
1613

1714
var telemetryForwarderPath = process.env.DD_TELEMETRY_FORWARDER_PATH
1815
if (typeof telemetryForwarderPath !== 'string' || !fs.existsSync(telemetryForwarderPath)) {
19-
module.exports = function () {}
16+
module.exports = function noop () {}
2017
}
2118

2219
var metadata = {
@@ -32,12 +29,12 @@ var seen = []
3229
function hasSeen (point) {
3330
if (point.name === 'abort') {
3431
// This one can only be sent once, regardless of tags
35-
return seen.includes('abort')
32+
return seen.indexOf('abort') !== -1
3633
}
3734
if (point.name === 'abort.integration') {
3835
// For now, this is the only other one we want to dedupe
3936
var compiledPoint = point.name + point.tags.join('')
40-
return seen.includes(compiledPoint)
37+
return seen.indexOf(compiledPoint) !== -1
4138
}
4239
return false
4340
}
@@ -48,7 +45,7 @@ function sendTelemetry (name, tags) {
4845
points = [{ name: name, tags: tags || [] }]
4946
}
5047
if (['1', 'true', 'True'].indexOf(process.env.DD_INJECT_FORCE) !== -1) {
51-
points = points.filter(function (p) { return ['error', 'complete'].includes(p.name) })
48+
points = points.filter(function (p) { return ['error', 'complete'].indexOf(p.name) !== -1 })
5249
}
5350
points = points.filter(function (p) { return !hasSeen(p) })
5451
for (var i = 0; i < points.length; i++) {

packages/dd-trace/src/guardrails/util.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
/* eslint-disable object-shorthand */
4-
53
function isTrue (str) {
64
str = String(str).toLowerCase()
75
return str === 'true' || str === '1'

version.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
'use strict'
22

3-
/* eslint-disable no-var */
4-
/* eslint-disable unicorn/prefer-number-properties */
5-
63
var version = require('./package.json').version
74
var ddMatches = version.match(/^(\d+)\.(\d+)\.(\d+)/)
85
var nodeMatches = process.versions.node.match(/^(\d+)\.(\d+)\.(\d+)/)

0 commit comments

Comments
 (0)