Skip to content

Commit 8de9ed2

Browse files
committed
chore(eslint): remove redundant iteration guards
## Summary Remove iteration guards where repository-owned callers always provide required collections. ## Why The Unicorn migration should only add defensive branches at genuinely optional or third-party boundaries. Keeping impossible checks would hide broken internal contracts. ## Test plan - Run the focused Bedrock, remote config, telemetry, WebdriverIO, Vitest, and Jest plugin suites. - Run `npm run lint`.
1 parent d4f8543 commit 8de9ed2

8 files changed

Lines changed: 69 additions & 95 deletions

File tree

packages/datadog-instrumentations/src/jest/coverage-backfill.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ const TRANSFORM_OPTIONS = {
1414

1515
function getCoverageBackfillFiles (skippableSuitesCoverage, rootDir, getTestSuitePath) {
1616
const files = []
17-
if (skippableSuitesCoverage) {
18-
for (const filename of Object.keys(skippableSuitesCoverage)) {
19-
const relativeFilename = path.isAbsolute(filename)
20-
? getTestSuitePath(filename, rootDir)
21-
: filename
22-
files.push(relativeFilename)
23-
}
17+
for (const filename of Object.keys(skippableSuitesCoverage)) {
18+
const relativeFilename = path.isAbsolute(filename)
19+
? getTestSuitePath(filename, rootDir)
20+
: filename
21+
files.push(relativeFilename)
2422
}
2523
return files
2624
}

packages/datadog-instrumentations/src/mocha/worker.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,9 @@ function getWebdriverioHookTest (hook) {
239239
*/
240240
function adjustWebdriverioHookFailures (runner) {
241241
let suppressedFailures = 0
242-
const failedHooks = runnerToFailedHooks.get(runner)
243-
if (failedHooks) {
244-
for (const { test } of failedHooks) {
245-
if (isWebdriverioFailureSuppressed(test)) {
246-
suppressedFailures++
247-
}
242+
for (const { test } of runnerToFailedHooks.get(runner)) {
243+
if (isWebdriverioFailureSuppressed(test)) {
244+
suppressedFailures++
248245
}
249246
}
250247
if (runner.stats) {
@@ -284,13 +281,10 @@ function getWebdriverioSuiteResults (runner) {
284281
}
285282
})
286283

287-
const failedHooks = runnerToFailedHooks.get(runner)
288-
if (failedHooks) {
289-
for (const { file, test } of failedHooks) {
290-
const result = resultsByFile.get(file)
291-
if (result && !isWebdriverioFailureSuppressed(test)) {
292-
result.status = 'fail'
293-
}
284+
for (const { file, test } of runnerToFailedHooks.get(runner)) {
285+
const result = resultsByFile.get(file)
286+
if (result && !isWebdriverioFailureSuppressed(test)) {
287+
result.status = 'fail'
294288
}
295289
}
296290

packages/datadog-instrumentations/src/vitest-worker.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,9 @@ function isFileInRepository (filename, repositoryRoot) {
137137
}
138138

139139
function isV8ScriptCovered (scriptCoverage) {
140-
if (scriptCoverage.functions) {
141-
for (const functionCoverage of scriptCoverage.functions) {
142-
if (functionCoverage.ranges) {
143-
for (const range of functionCoverage.ranges) {
144-
if (range.count > 0) return true
145-
}
146-
}
140+
for (const functionCoverage of scriptCoverage.functions) {
141+
for (const range of functionCoverage.ranges) {
142+
if (range.count > 0) return true
147143
}
148144
}
149145
return false

packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -650,31 +650,29 @@ function extractTextAndResponseReasonConverseFromStream (chunks) {
650650
let usage = {}
651651
const blocksByIdx = new Map()
652652

653-
if (chunks) {
654-
for (const chunk of chunks) {
655-
if (chunk.messageStart?.role) {
656-
role = chunk.messageStart.role
657-
} else if (chunk.messageStop?.stopReason) {
658-
stopReason = chunk.messageStop.stopReason
659-
} else if (chunk.metadata?.usage) {
660-
usage = chunk.metadata.usage
661-
} else if (chunk.contentBlockStart?.start?.toolUse) {
662-
const { contentBlockIndex, start: { toolUse } } = chunk.contentBlockStart
663-
blocksByIdx.set(contentBlockIndex, {
664-
toolUse: { toolUseId: toolUse.toolUseId, name: toolUse.name, inputStr: '' },
665-
})
666-
} else if (chunk.contentBlockDelta) {
667-
const { contentBlockIndex, delta } = chunk.contentBlockDelta
668-
if (typeof delta?.text === 'string') {
669-
const block = blocksByIdx.get(contentBlockIndex) ?? {}
670-
block.text = (block.text ?? '') + delta.text
671-
blocksByIdx.set(contentBlockIndex, block)
672-
} else if (typeof delta?.toolUse?.input === 'string') {
673-
const block = blocksByIdx.get(contentBlockIndex) ?? { toolUse: { inputStr: '' } }
674-
block.toolUse ??= { inputStr: '' }
675-
block.toolUse.inputStr += delta.toolUse.input
676-
blocksByIdx.set(contentBlockIndex, block)
677-
}
653+
for (const chunk of chunks) {
654+
if (chunk.messageStart?.role) {
655+
role = chunk.messageStart.role
656+
} else if (chunk.messageStop?.stopReason) {
657+
stopReason = chunk.messageStop.stopReason
658+
} else if (chunk.metadata?.usage) {
659+
usage = chunk.metadata.usage
660+
} else if (chunk.contentBlockStart?.start?.toolUse) {
661+
const { contentBlockIndex, start: { toolUse } } = chunk.contentBlockStart
662+
blocksByIdx.set(contentBlockIndex, {
663+
toolUse: { toolUseId: toolUse.toolUseId, name: toolUse.name, inputStr: '' },
664+
})
665+
} else if (chunk.contentBlockDelta) {
666+
const { contentBlockIndex, delta } = chunk.contentBlockDelta
667+
if (typeof delta?.text === 'string') {
668+
const block = blocksByIdx.get(contentBlockIndex) ?? {}
669+
block.text = (block.text ?? '') + delta.text
670+
blocksByIdx.set(contentBlockIndex, block)
671+
} else if (typeof delta?.toolUse?.input === 'string') {
672+
const block = blocksByIdx.get(contentBlockIndex) ?? { toolUse: { inputStr: '' } }
673+
block.toolUse ??= { inputStr: '' }
674+
block.toolUse.inputStr += delta.toolUse.input
675+
blocksByIdx.set(contentBlockIndex, block)
678676
}
679677
}
680678
}

packages/datadog-plugin-mocha/src/index.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -767,28 +767,22 @@ class MochaPlugin extends CiPlugin {
767767
const state = this._webdriverioJasmineState
768768
const results = []
769769
const reportedFiles = new Set()
770-
const suiteStatuses = state?.suiteStatuses
771-
if (suiteStatuses) {
772-
for (const [file, status] of suiteStatuses) {
773-
const error = state.suiteErrors.get(file)
774-
const result = { file, status }
775-
if (error) {
776-
result.error = {
777-
message: error.message,
778-
stack: error.stack,
779-
}
770+
for (const [file, status] of state.suiteStatuses) {
771+
const error = state.suiteErrors.get(file)
772+
const result = { file, status }
773+
if (error) {
774+
result.error = {
775+
message: error.message,
776+
stack: error.stack,
780777
}
781-
results.push(result)
782-
reportedFiles.add(file)
783778
}
779+
results.push(result)
780+
reportedFiles.add(file)
784781
}
785-
const specs = state?.specs
786-
if (specs) {
787-
for (const spec of specs) {
788-
const file = normalizeJasmineFile(spec)
789-
if (!reportedFiles.has(file)) {
790-
results.push({ file, status: 'skip' })
791-
}
782+
for (const spec of state.specs) {
783+
const file = normalizeJasmineFile(spec)
784+
if (!reportedFiles.has(file)) {
785+
results.push({ file, status: 'skip' })
792786
}
793787
}
794788

packages/datadog-plugin-vitest/src/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,9 @@ class VitestPlugin extends CiPlugin {
593593
isVitestNoWorkerInitActive,
594594
onDone,
595595
}) => {
596-
if (requestErrorTags) {
597-
for (const [tag, value] of Object.entries(requestErrorTags)) {
598-
this.testSessionSpan.setTag(tag, value)
599-
this.testModuleSpan.setTag(tag, value)
600-
}
596+
for (const [tag, value] of Object.entries(requestErrorTags)) {
597+
this.testSessionSpan.setTag(tag, value)
598+
this.testModuleSpan.setTag(tag, value)
601599
}
602600
this.testSessionSpan.setTag(TEST_STATUS, status)
603601
this.testModuleSpan.setTag(TEST_STATUS, status)

packages/dd-trace/src/config/remote_config.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,13 @@ const optionLookupTable = {
236236

237237
const transformers = {
238238
tracing_sampling_rules (samplingRules) {
239-
if (samplingRules) {
240-
for (const rule of (samplingRules)) {
241-
if (rule.tags) {
242-
const reformattedTags = {}
243-
for (const tag of rule.tags) {
244-
reformattedTags[tag.key] = tag.value_glob
245-
}
246-
rule.tags = reformattedTags
239+
for (const rule of samplingRules) {
240+
if (rule.tags) {
241+
const reformattedTags = {}
242+
for (const tag of rule.tags) {
243+
reformattedTags[tag.key] = tag.value_glob
247244
}
245+
rule.tags = reformattedTags
248246
}
249247
}
250248
return samplingRules

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,15 @@ function updateRetryData (error, retryObj) {
130130

131131
function getIntegrations () {
132132
const newIntegrations = /** @type {Integration[]} */ ([])
133-
if ((pluginManager._pluginsByName) != null) {
134-
for (const pluginName of Object.keys(pluginManager._pluginsByName)) {
135-
if (!sentIntegrations.has(pluginName)) {
136-
newIntegrations.push({
137-
name: pluginName,
138-
enabled: pluginManager._pluginsByName[pluginName]._enabled,
139-
auto_enabled: true,
140-
[processTags.TELEMETRY_FIELD_NAME]: processTags.tagsObject,
141-
})
142-
sentIntegrations.add(pluginName)
143-
}
133+
for (const pluginName of Object.keys(pluginManager._pluginsByName)) {
134+
if (!sentIntegrations.has(pluginName)) {
135+
newIntegrations.push({
136+
name: pluginName,
137+
enabled: pluginManager._pluginsByName[pluginName]._enabled,
138+
auto_enabled: true,
139+
[processTags.TELEMETRY_FIELD_NAME]: processTags.tagsObject,
140+
})
141+
sentIntegrations.add(pluginName)
144142
}
145143
}
146144
return newIntegrations

0 commit comments

Comments
 (0)