-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathnormalize.ts
More file actions
41 lines (38 loc) · 1.01 KB
/
Copy pathnormalize.ts
File metadata and controls
41 lines (38 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import type { AuditOutputs, Issue } from '@code-pushup/models';
import { formatGitPath, getGitRoot, isFileIssue } from '@code-pushup/utils';
export function normalizeIssue(issue: Issue, gitRoot: string): Issue {
// Early exit to avoid cloning; only file sources need path normalization
if (!isFileIssue(issue)) {
return issue;
}
const { source, ...issueWithoutSource } = issue;
return {
...issueWithoutSource,
source: {
...source,
file: formatGitPath(source.file, gitRoot),
},
};
}
export async function normalizeAuditOutputs(
audits: AuditOutputs,
): Promise<AuditOutputs> {
const gitRoot = await getGitRoot();
return audits.map(audit => {
if (
audit.details?.issues == null ||
audit.details.issues.every(issue => issue.source == null)
) {
return audit;
}
return {
...audit,
details: {
...audit.details,
issues: audit.details.issues.map(issue =>
normalizeIssue(issue, gitRoot),
),
},
};
});
}