Skip to content

Commit 17724f8

Browse files
authored
Use more loop labels in fix (#560)
1 parent 5514dce commit 17724f8

2 files changed

Lines changed: 28 additions & 28 deletions

File tree

src/commands/fix/npm-fix.mts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export async function npmFix(
137137
const sortedInfoEntries = [...infoByPkgName.entries()].sort((a, b) =>
138138
naturalCompare(a[0], b[0])
139139
)
140-
infoByPkgNameLoop: for (const { 0: name, 1: infos } of sortedInfoEntries) {
140+
infoEntriesLoop: for (const { 0: name, 1: infos } of sortedInfoEntries) {
141141
logger.log(`Processing vulnerable package: ${name}`)
142142
logger.indent()
143143
spinner?.indent()
@@ -151,13 +151,13 @@ export async function npmFix(
151151
logger.warn(`Unexpected condition: No packument found for ${name}\n`)
152152
logger.dedent()
153153
spinner?.dedent()
154-
continue
154+
continue infoEntriesLoop
155155
}
156156

157157
const availableVersions = Object.keys(packument.versions)
158158
const warningsForAfter = new Set<string>()
159159

160-
for (const pkgJsonPath of pkgJsonPaths) {
160+
pkgJsonPathsLoop: for (const pkgJsonPath of pkgJsonPaths) {
161161
const pkgPath = path.dirname(pkgJsonPath)
162162
const isWorkspaceRoot =
163163
pkgJsonPath === pkgEnvDetails.editablePkgJson.filename
@@ -180,7 +180,7 @@ export async function npmFix(
180180
logger.warn(
181181
`Unexpected condition: Lockfile entries not found for ${name}.\n`
182182
)
183-
continue
183+
continue pkgJsonPathsLoop
184184
}
185185

186186
// Always re-read the editable package.json to avoid stale mutations
@@ -190,7 +190,7 @@ export async function npmFix(
190190
editable: true
191191
})
192192

193-
for (const oldVersion of oldVersions) {
193+
oldVersionsLoop: for (const oldVersion of oldVersions) {
194194
const oldId = `${name}@${oldVersion}`
195195
const oldPurl = idToPurl(oldId)
196196

@@ -199,10 +199,10 @@ export async function npmFix(
199199
logger.warn(
200200
`Unexpected condition: Arborist node not found, skipping ${oldId}`
201201
)
202-
continue
202+
continue oldVersionsLoop
203203
}
204204

205-
for (const {
205+
infosLoop: for (const {
206206
firstPatchedVersionIdentifier,
207207
vulnerableVersionRange
208208
} of infos.values()) {
@@ -220,7 +220,7 @@ export async function npmFix(
220220
warningsForAfter.add(
221221
`No update applied. ${oldId} needs >=${firstPatchedVersionIdentifier}`
222222
)
223-
continue
223+
continue infosLoop
224224
}
225225

226226
const newVersionRange = applyRange(oldVersion, newVersion, rangeStyle)
@@ -258,7 +258,7 @@ export async function npmFix(
258258
// eslint-disable-next-line no-await-in-loop
259259
actualTree = await install(arb, { cwd })
260260
}
261-
continue
261+
continue infosLoop
262262
}
263263

264264
spinner?.start()
@@ -291,14 +291,14 @@ export async function npmFix(
291291
// eslint-disable-next-line no-await-in-loop
292292
if (await prExistForBranch(owner, repo, branch)) {
293293
debugLog(`Branch "${branch}" exists, skipping PR creation.`)
294-
continue
294+
continue infosLoop
295295
}
296296
// eslint-disable-next-line no-await-in-loop
297297
if (await gitRemoteBranchExists(branch, cwd)) {
298298
debugLog(
299299
`Remote branch "${branch}" exists, skipping PR creation.`
300300
)
301-
continue
301+
continue infosLoop
302302
}
303303

304304
const moddedFilepaths =
@@ -314,7 +314,7 @@ export async function npmFix(
314314
logger.warn(
315315
'Unexpected condition: Nothing to commit, skipping PR creation.'
316316
)
317-
continue
317+
continue infosLoop
318318
}
319319

320320
if (
@@ -329,7 +329,7 @@ export async function npmFix(
329329
logger.warn(
330330
'Unexpected condition: Push failed, skipping PR creation.'
331331
)
332-
continue
332+
continue infosLoop
333333
}
334334
// eslint-disable-next-line no-await-in-loop
335335
await cleanupOpenPrs(owner, repo, oldPurl, newVersion, {
@@ -385,7 +385,7 @@ export async function npmFix(
385385
)
386386
}
387387
if (++count >= limit) {
388-
break infoByPkgNameLoop
388+
break infoEntriesLoop
389389
}
390390
}
391391
}

src/commands/fix/pnpm-fix.mts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export async function pnpmFix(
197197
const sortedInfoEntries = [...infoByPkgName.entries()].sort((a, b) =>
198198
naturalCompare(a[0], b[0])
199199
)
200-
infoByPkgNameLoop: for (const { 0: name, 1: infos } of sortedInfoEntries) {
200+
infoEntriesLoop: for (const { 0: name, 1: infos } of sortedInfoEntries) {
201201
logger.log(`Processing vulnerable package: ${name}`)
202202
logger.indent()
203203
spinner?.indent()
@@ -211,13 +211,13 @@ export async function pnpmFix(
211211
logger.warn(`Unexpected condition: No packument found for ${name}\n`)
212212
logger.dedent()
213213
spinner?.dedent()
214-
continue
214+
continue infoEntriesLoop
215215
}
216216

217217
const availableVersions = Object.keys(packument.versions)
218218
const warningsForAfter = new Set<string>()
219219

220-
for (const pkgJsonPath of pkgJsonPaths) {
220+
pkgJsonPathsLoop: for (const pkgJsonPath of pkgJsonPaths) {
221221
const pkgPath = path.dirname(pkgJsonPath)
222222
const isWorkspaceRoot =
223223
pkgJsonPath === pkgEnvDetails.editablePkgJson.filename
@@ -240,7 +240,7 @@ export async function pnpmFix(
240240
logger.warn(
241241
`Unexpected condition: Lockfile entries not found for ${name}.\n`
242242
)
243-
continue
243+
continue pkgJsonPathsLoop
244244
}
245245

246246
// Always re-read the editable package.json to avoid stale mutations
@@ -258,7 +258,7 @@ export async function pnpmFix(
258258
| Record<string, string>
259259
| undefined
260260

261-
for (const oldVersion of oldVersions) {
261+
oldVersionsLoop: for (const oldVersion of oldVersions) {
262262
const oldId = `${name}@${oldVersion}`
263263
const oldPurl = idToPurl(oldId)
264264

@@ -267,9 +267,9 @@ export async function pnpmFix(
267267
logger.warn(
268268
`Unexpected condition: Arborist node not found, skipping ${oldId}`
269269
)
270-
continue
270+
continue oldVersionsLoop
271271
}
272-
for (const {
272+
infosLoop: for (const {
273273
firstPatchedVersionIdentifier,
274274
vulnerableVersionRange
275275
} of infos.values()) {
@@ -287,7 +287,7 @@ export async function pnpmFix(
287287
warningsForAfter.add(
288288
`No update applied. ${oldId} needs >=${firstPatchedVersionIdentifier}`
289289
)
290-
continue
290+
continue infosLoop
291291
}
292292

293293
const overrideKey = `${name}@${vulnerableVersionRange}`
@@ -357,7 +357,7 @@ export async function pnpmFix(
357357
// eslint-disable-next-line no-await-in-loop
358358
actualTree = await install(pkgEnvDetails, { cwd, spinner })
359359
}
360-
continue
360+
continue infosLoop
361361
}
362362

363363
spinner?.start()
@@ -391,14 +391,14 @@ export async function pnpmFix(
391391
// eslint-disable-next-line no-await-in-loop
392392
if (await prExistForBranch(owner, repo, branch)) {
393393
debugLog(`Branch "${branch}" exists, skipping PR creation.`)
394-
continue
394+
continue infosLoop
395395
}
396396
// eslint-disable-next-line no-await-in-loop
397397
if (await gitRemoteBranchExists(branch, cwd)) {
398398
debugLog(
399399
`Remote branch "${branch}" exists, skipping PR creation.`
400400
)
401-
continue
401+
continue infosLoop
402402
}
403403

404404
const moddedFilepaths =
@@ -413,7 +413,7 @@ export async function pnpmFix(
413413
logger.warn(
414414
'Unexpected condition: Nothing to commit, skipping PR creation.'
415415
)
416-
continue
416+
continue infosLoop
417417
}
418418

419419
if (
@@ -428,7 +428,7 @@ export async function pnpmFix(
428428
logger.warn(
429429
'Unexpected condition: Push failed, skipping PR creation.'
430430
)
431-
continue
431+
continue infosLoop
432432
}
433433
// eslint-disable-next-line no-await-in-loop
434434
await cleanupOpenPrs(owner, repo, oldPurl, newVersion, {
@@ -484,7 +484,7 @@ export async function pnpmFix(
484484
)
485485
}
486486
if (++count >= limit) {
487-
break infoByPkgNameLoop
487+
break infoEntriesLoop
488488
}
489489
}
490490
}

0 commit comments

Comments
 (0)