Skip to content

Commit a1fafbd

Browse files
committed
chore(eslint): refine unicorn rule selection
Keep negated array predicates disabled because the inverted forms obscure existing preconditions. Preserve explicit string coercion only where values are not guaranteed to be strings.
1 parent 028ae9f commit a1fafbd

58 files changed

Lines changed: 81 additions & 84 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ci/diagnose.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ function findScriptMatches (scripts, patterns) {
13941394

13951395
for (const script of scripts) {
13961396
if (!/test|spec|e2e|integration|unit/i.test(script.name) &&
1397-
patterns.every(pattern => !pattern.test(script.command))) {
1397+
!patterns.some(pattern => pattern.test(script.command))) {
13981398
continue
13991399
}
14001400

ci/test-optimization-validation/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ function getValidationCoverage ({ results, requestedScenario, frameworks, scenar
546546
if (runnableFrameworks.length === 0) return 'partial'
547547
for (const framework of runnableFrameworks) {
548548
for (const scenario of scenarios) {
549-
if (results.every(result => !(result.frameworkId === framework.id && result.scenario === scenario))) {
549+
if (!results.some(result => result.frameworkId === framework.id && result.scenario === scenario)) {
550550
return 'partial'
551551
}
552552
}

ci/test-optimization-validation/command-runner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ function runCommand (command, options = {}) {
215215
child.stdout.on('data', chunk => {
216216
const capture = appendCapturedOutput(result.stdout, chunk, maxOutputBytes)
217217
result.stdout = capture.output
218-
result.stdoutTruncated = result.stdoutTruncated || capture.truncated
218+
result.stdoutTruncated ||= capture.truncated
219219
})
220220
child.stderr.on('data', chunk => {
221221
const capture = appendCapturedOutput(result.stderr, chunk, maxOutputBytes)
222222
result.stderr = capture.output
223-
result.stderrTruncated = result.stderrTruncated || capture.truncated
223+
result.stderrTruncated ||= capture.truncated
224224
})
225225
child.on('error', err => {
226226
result.stderr += `${err.stack || err}\n`

ci/test-optimization-validation/command-suitability.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function getVitestGeneratedPathError (command, framework, repositoryRoot) {
183183
const relative = path.relative(path.dirname(configFile), file.path).split(path.sep).join('/')
184184
if (relative === '..' || relative.startsWith('../') || path.isAbsolute(relative)) continue
185185

186-
if (includes.length > 0 && includes.every(pattern => !matchesGlob(relative, pattern))) {
186+
if (includes.length > 0 && !includes.some(pattern => matchesGlob(relative, pattern))) {
187187
return `uses temporary test path ${file.path}, which does not match the literal test.include patterns in ` +
188188
`${configFile}: ${includes.join(', ')}. Choose a temporary test path accepted by the selected Vitest ` +
189189
'config ' +

ci/test-optimization-validation/plan-writer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ function appendApprovalSummaryFramework (lines, framework, requestedScenario, re
406406
lines.push('**Temporary test source:**', '')
407407
for (const file of strategy.files || []) {
408408
lines.push(
409-
`${inlineCode(getRepositoryRelativePath(repositoryRoot, file.path))}`,
409+
inlineCode(getRepositoryRelativePath(repositoryRoot, file.path)),
410410
'',
411411
codeBlock(file.contentLines.join('\n')),
412412
''

ci/test-optimization-validation/report-writer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ function getResultDetailLines (result, options = {}) {
845845

846846
function getCommonArtifactDirectory (artifacts) {
847847
let directory = path.dirname(path.resolve(artifacts[0]))
848-
while (artifacts.some(artifact => !isPathInside(directory, path.resolve(artifact)))) {
848+
while (!artifacts.every(artifact => isPathInside(directory, path.resolve(artifact)))) {
849849
const parent = path.dirname(directory)
850850
if (parent === directory) return directory
851851
directory = parent

ci/test-optimization-validation/scenarios/ci-wiring.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ function getNodeOptionsRemovalDiagnosis ({ basicResult, evidence, framework }) {
338338
: ''
339339

340340
return 'The CI test command ran tests, but no Test Optimization events reached the offline event artifact. ' +
341-
`${ciCommand}` +
341+
ciCommand +
342342
`${source} expands to \`${finding.command}\`. The empty \`NODE_OPTIONS=\` assignment clears the Datadog ` +
343343
`preload before ${frameworkName} starts.${directResult}`
344344
}

ci/test-optimization-validation/scenarios/test-management.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function buildQuarantinedResponse (framework, scenario, discoveredIdentities = [
148148
for (const identity of identities) {
149149
for (const suite of getSuiteCandidates(identity, scenario)) {
150150
for (const name of getNameCandidates(identity)) {
151-
suites[suite] = suites[suite] || { tests: {} }
151+
suites[suite] ||= { tests: {} }
152152
suites[suite].tests[name] = {
153153
properties: {
154154
quarantined: true,

eslint.config.mjs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ export default [
651651
'unicorn/no-array-splice': 'off', // toSpliced copies the whole array (perf)
652652
'unicorn/no-break-in-nested-loop': 'off', // Conflicts with our performance-oriented loops
653653
'unicorn/no-global-object-property-assignment': 'off', // We use globalThis[Symbol.for('dd-trace')]
654+
'unicorn/no-negated-array-predicate': 'off', // Predicate inversion is harder to read and creates churn
654655
'unicorn/no-nested-ternary': 'off', // Not really an issue in the code and the benefit is small
655656
'unicorn/no-new-array': 'off', // new Array is often used for performance reasons
656657
'unicorn/no-null': 'off', // We do not control external APIs and it is hard to differentiate these
@@ -678,17 +679,12 @@ export default [
678679
'unicorn/switch-case-braces': 'off', // Questionable benefit
679680

680681
// These remaining rules need focused rewrites before activation (counts from the v72 run).
681-
'unicorn/logical-assignment-operators': 'off', // 51 errors | matches our ??=/||= usage
682682
'unicorn/no-confusing-array-splice': 'off', // 1 error
683683
'unicorn/no-for-each': 'off', // 10 errors | we already prefer for-of in production
684684
'unicorn/no-negated-comparison': 'off', // 1 error
685685
'unicorn/no-subtraction-comparison': 'off', // 2 errors
686686
'unicorn/no-unnecessary-global-this': 'off', // 3 errors | explicit globals are clearer
687-
'unicorn/no-unnecessary-splice': 'off', // 2 errors
688-
'unicorn/no-useless-concat': 'off', // 4 errors
689687
'unicorn/no-useless-continue': 'off', // 1 error
690-
'unicorn/no-useless-delete-check': 'off', // 1 error
691-
'unicorn/no-useless-template-literals': 'off', // 16 errors | String() rewrites reduce readability
692688
'unicorn/prefer-array-from-map': 'off', // 9 errors | loops avoid callback allocation
693689
'unicorn/prefer-continue': 'off', // 52 errors
694690
'unicorn/prefer-logical-operator-over-ternary': 'off', // 3 errors

packages/datadog-esbuild/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ ${build.initialOptions.banner.js}`
268268
let pathToPackageJson
269269
try {
270270
// we can't use require.resolve('pkg/package.json') as ESM modules don't make the file available
271-
pathToPackageJson = require.resolve(`${extracted.pkg}`, { paths: [args.resolveDir] })
271+
pathToPackageJson = require.resolve(extracted.pkg, { paths: [args.resolveDir] })
272272
pathToPackageJson = extractPackageAndModulePath(pathToPackageJson).pkgJson
273273
} catch (err) {
274274
if (err.code === 'MODULE_NOT_FOUND') {

0 commit comments

Comments
 (0)