From b7a66f25b3f365a513c8c991e2f1361744c27e83 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 22 Oct 2026 00:46:11 +0000 Subject: [PATCH] [Refactor] Group security issues declaratively with groupBy Replace the manual Map accumulation in groupIssues with the cli-kit groupBy helper, deriving each group's issues and distinct files from the grouped entries instead of mutating accumulator arrays. Co-Authored-By: Claude Opus 4.8 --- .../app-security-engine/output/group-issues.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/app/src/cli/services/app-security-engine/output/group-issues.ts b/packages/app/src/cli/services/app-security-engine/output/group-issues.ts index 7575aa53572..ec7767b8a58 100644 --- a/packages/app/src/cli/services/app-security-engine/output/group-issues.ts +++ b/packages/app/src/cli/services/app-security-engine/output/group-issues.ts @@ -1,4 +1,5 @@ import {SEVERITY_RANK, type Issue, type Severity, type SkippedFile} from '../types.js' +import {groupBy} from '@shopify/cli-kit/common/collection' export interface IssueGroup { severity: Severity @@ -12,7 +13,6 @@ function groupKey(issue: Issue): string { /** A presentation view only: never replace scan issues or deterministic-findings.json findings with these groups. */ export function groupIssues(issues: Issue[]): IssueGroup[] { - const groups = new Map() const sorted = [...issues].sort( (left, right) => SEVERITY_RANK[right.severity] - SEVERITY_RANK[left.severity] || @@ -22,17 +22,11 @@ export function groupIssues(issues: Issue[]): IssueGroup[] { left.id.localeCompare(right.id) || left.title.localeCompare(right.title), ) - for (const issue of sorted) { - const key = groupKey(issue) - const group = groups.get(key) - if (group) { - group.issues.push(issue) - if (!group.files.includes(issue.location.file)) group.files.push(issue.location.file) - } else { - groups.set(key, {severity: issue.severity, issues: [issue], files: [issue.location.file]}) - } - } - return [...groups.values()] + return Object.values(groupBy(sorted, groupKey)).map((groupedIssues) => ({ + severity: groupedIssues[0]!.severity, + issues: groupedIssues, + files: [...new Set(groupedIssues.map((issue) => issue.location.file))], + })) } /** How many files the deterministic scan skipped, by reason. */