({
currReport,
prevReport,
reportsDiff,
changedFiles,
}: {
currReport: Report;
prevReport: Report;
reportsDiff: ReportsDiff;
changedFiles: ChangedFiles;
})
| 25 | type IssueCompareFn = (a: SourceFileIssue, b: SourceFileIssue) => number; |
| 26 | |
| 27 | export function filterRelevantIssues({ |
| 28 | currReport, |
| 29 | prevReport, |
| 30 | reportsDiff, |
| 31 | changedFiles, |
| 32 | }: { |
| 33 | currReport: Report; |
| 34 | prevReport: Report; |
| 35 | reportsDiff: ReportsDiff; |
| 36 | changedFiles: ChangedFiles; |
| 37 | }): SourceFileIssue[] { |
| 38 | const auditsWithPlugin = [ |
| 39 | ...reportsDiff.audits.changed, |
| 40 | ...reportsDiff.audits.added, |
| 41 | ] |
| 42 | .map((auditLink): [PluginMeta, AuditReport] | undefined => { |
| 43 | const plugin = currReport.plugins.find( |
| 44 | ({ slug }) => slug === auditLink.plugin.slug, |
| 45 | ); |
| 46 | const audit = plugin?.audits.find(({ slug }) => slug === auditLink.slug); |
| 47 | return plugin && audit && [plugin, audit]; |
| 48 | }) |
| 49 | .filter((ctx): ctx is [PluginMeta, AuditReport] => ctx != null); |
| 50 | |
| 51 | const issues = auditsWithPlugin.flatMap(([plugin, audit]) => |
| 52 | getAuditIssues(audit, plugin), |
| 53 | ); |
| 54 | const prevIssues = prevReport.plugins.flatMap(plugin => |
| 55 | plugin.audits.flatMap(audit => getAuditIssues(audit, plugin)), |
| 56 | ); |
| 57 | |
| 58 | return issues |
| 59 | .filter( |
| 60 | issue => |
| 61 | isFileChanged(changedFiles, issue.source.file) && |
| 62 | !prevIssues.some(prevIssue => |
| 63 | issuesMatch(prevIssue, issue, changedFiles), |
| 64 | ), |
| 65 | ) |
| 66 | .sort(createIssuesSortCompareFn(currReport)); |
| 67 | } |
| 68 | |
| 69 | function getAuditIssues( |
| 70 | audit: AuditReport, |
no test coverage detected