Skip to content

Commit 5a8eedf

Browse files
committed
Don't dim alerts
1 parent 8a27ad0 commit 5a8eedf

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/utils/socket-package-alert.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,10 @@ export function logAlertsMap(
371371
const sortedEntries = [...alertsMap.entries()].sort(
372372
(a, b) => getAlertsSeverityOrder(a[1]) - getAlertsSeverityOrder(b[1])
373373
)
374+
let mentionedHiddenCount = 0
374375
const hiddenEntries: typeof sortedEntries = []
375376
for (
376-
let i = 0, prevDimmed = false, { length } = sortedEntries;
377+
let i = 0, prevBelowTheFold = false, { length } = sortedEntries;
377378
i < length;
378379
i += 1
379380
) {
@@ -395,7 +396,7 @@ export function logAlertsMap(
395396
}
396397
const lines = new Set<string>()
397398
const sortedAlerts = filteredAlerts.sort(alertSeverityComparator)
398-
const isDimmed = !sortedAlerts.find(
399+
const isBelowTheFold = !sortedAlerts.find(
399400
a => a.blocked || getAlertSeverityOrder(a) < ALERT_SEVERITY_ORDER.middle
400401
)
401402
for (const alert of sortedAlerts) {
@@ -418,11 +419,7 @@ export function logAlertsMap(
418419
const maybeDesc = info?.description ? ` - ${info.description}` : ''
419420
const content = `${title}${maybeAttributes}${maybeDesc}`
420421
// TODO: emoji seems to mis-align terminals sometimes
421-
if (isDimmed) {
422-
lines.add(` ${colors.dim(content)}`)
423-
} else {
424-
lines.add(` ${content}`)
425-
}
422+
lines.add(` ${content}`)
426423
}
427424

428425
const purlObj = PackageURL.fromString(`pkg:npm/${pkgId}`)
@@ -434,8 +431,8 @@ export function logAlertsMap(
434431
purlObj.version
435432
)
436433
)
437-
if (isDimmed) {
438-
output.write(`${prevDimmed ? '' : '\n'}${colors.dim(`${hyperlink}:`)}\n`)
434+
if (isBelowTheFold) {
435+
output.write(`${prevBelowTheFold ? '' : '\n'}${hyperlink}:\n`)
439436
} else {
440437
output.write(`${i ? '\n' : ''}${hyperlink}:\n`)
441438
}
@@ -444,6 +441,7 @@ export function logAlertsMap(
444441
}
445442
const { length: hiddenAlertsCount } = hiddenAlerts
446443
if (hiddenAlertsCount) {
444+
mentionedHiddenCount += 1
447445
if (hiddenAlertsCount === 1) {
448446
output.write(
449447
` ${colors.dim(`+1 Hidden ${getSeverityLabel(hiddenAlerts[0]!.raw.severity ?? 'low')} risk alert`)}\n`
@@ -454,10 +452,10 @@ export function logAlertsMap(
454452
)
455453
}
456454
}
457-
prevDimmed = isDimmed
455+
prevBelowTheFold = isBelowTheFold
458456
}
459-
const { length: hiddenEntriesCount } = hiddenEntries
460-
if (hiddenEntriesCount) {
457+
const additionalHiddenCount = hiddenEntries.length - mentionedHiddenCount
458+
if (additionalHiddenCount) {
461459
const totalRiskCounts = {
462460
critical: 0,
463461
high: 0,
@@ -472,7 +470,7 @@ export function logAlertsMap(
472470
totalRiskCounts.low += riskCounts.low
473471
}
474472
output.write(
475-
`\n${colors.dim(`+${hiddenEntriesCount} Packages with hidden alerts ${colors.italic(getHiddenRisksDescription(totalRiskCounts))}`)}\n`
473+
`\n${colors.dim(`+${additionalHiddenCount} Packages with hidden alerts ${colors.italic(getHiddenRisksDescription(totalRiskCounts))}`)}\n`
476474
)
477475
}
478476
output.write('\n')

0 commit comments

Comments
 (0)