@code-pushup/core
Advanced tools
Comparing version 0.8.9 to 0.8.10
99
index.js
@@ -811,3 +811,3 @@ // packages/core/src/lib/implementation/persist.ts | ||
); | ||
const audits = groupAudits.sort(sortCategoryAudits); | ||
const audits = groupAudits.sort(compareCategoryAudits); | ||
return { | ||
@@ -818,3 +818,3 @@ ...groupWithAudits, | ||
} | ||
function sortCategoryAudits(a, b) { | ||
function compareCategoryAudits(a, b) { | ||
if (a.weight !== b.weight) { | ||
@@ -831,3 +831,3 @@ return b.weight - a.weight; | ||
} | ||
function sortAudits(a, b) { | ||
function compareAudits(a, b) { | ||
if (a.score !== b.score) { | ||
@@ -1126,19 +1126,14 @@ return a.score - b.score; | ||
const categoryDocs = getDocsAndDescription(category); | ||
const auditsAndGroups = category.refs.reduce( | ||
(acc2, ref) => ({ | ||
...acc2, | ||
...ref.type === "group" ? { | ||
groups: [ | ||
...acc2.groups, | ||
getGroupWithAudits(ref.slug, ref.plugin, plugins) | ||
] | ||
} : { | ||
audits: [...acc2.audits, getAuditByRef(ref, plugins)] | ||
} | ||
}), | ||
{ groups: [], audits: [] } | ||
); | ||
const audits = auditsAndGroups.audits.sort(sortCategoryAudits).map((audit) => auditItemToCategorySection(audit, plugins)).join(NEW_LINE); | ||
const groups = auditsAndGroups.groups.map((group) => groupItemToCategorySection(group, plugins)).join(""); | ||
return acc + NEW_LINE + categoryTitle + NEW_LINE + NEW_LINE + categoryDocs + categoryScore + NEW_LINE + groups + NEW_LINE + audits; | ||
const categoryMDItems = category.refs.reduce((acc2, ref) => { | ||
if (ref.type === "group") { | ||
const group = getGroupWithAudits(ref.slug, ref.plugin, plugins); | ||
const mdGroupItem = groupItemToCategorySection(group, plugins); | ||
return acc2 + mdGroupItem + NEW_LINE; | ||
} else { | ||
const audit = getAuditByRef(ref, plugins); | ||
const mdAuditItem = auditItemToCategorySection(audit, plugins); | ||
return acc2 + mdAuditItem + NEW_LINE; | ||
} | ||
}, ""); | ||
return acc + NEW_LINE + categoryTitle + NEW_LINE + NEW_LINE + categoryDocs + categoryScore + NEW_LINE + categoryMDItems; | ||
}, ""); | ||
@@ -1182,3 +1177,3 @@ return h2("\u{1F3F7} Categories") + NEW_LINE + categoryDetails; | ||
const auditsSection = report.plugins.reduce((acc, plugin) => { | ||
const auditsData = plugin.audits.sort(sortAudits).reduce((acc2, audit) => { | ||
const auditsData = plugin.audits.reduce((acc2, audit) => { | ||
const auditTitle = `${audit.title} (${getPluginNameFromSlug( | ||
@@ -1206,3 +1201,3 @@ audit.plugin, | ||
detailsTableHeaders, | ||
...audit.details.issues.sort(compareIssues).map((issue) => { | ||
...audit.details.issues.map((issue) => { | ||
const severity = `${getSeverityIcon(issue.severity)} <i>${issue.severity}</i>`; | ||
@@ -1311,3 +1306,3 @@ const message = issue.message; | ||
const ui = cliui({ width: 80 }); | ||
audits.sort(sortAudits).forEach(({ score, title: title2, displayValue, value }) => { | ||
audits.forEach(({ score, title: title2, displayValue, value }) => { | ||
ui.div( | ||
@@ -1472,2 +1467,52 @@ { | ||
// packages/utils/src/lib/sort-report.ts | ||
function sortReport(report) { | ||
const { categories, plugins } = report; | ||
const sortedCategories = categories.map((category) => { | ||
const { audits, groups } = category.refs.reduce( | ||
(acc, ref) => ({ | ||
...acc, | ||
...ref.type === "group" ? { | ||
groups: [ | ||
...acc.groups, | ||
getGroupWithAudits(ref.slug, ref.plugin, plugins) | ||
] | ||
} : { | ||
audits: [...acc.audits, getAuditByRef(ref, plugins)] | ||
} | ||
}), | ||
{ groups: [], audits: [] } | ||
); | ||
const sortedAuditsAndGroups = [ | ||
...groups, | ||
...audits.sort(compareCategoryAudits) | ||
]; | ||
const sortedRefs = category.refs.slice().sort((a, b) => { | ||
const aIndex = sortedAuditsAndGroups.findIndex( | ||
(ref) => ref.slug === a.slug | ||
); | ||
const bIndex = sortedAuditsAndGroups.findIndex( | ||
(ref) => ref.slug === b.slug | ||
); | ||
return aIndex - bIndex; | ||
}); | ||
return { ...category, refs: sortedRefs }; | ||
}); | ||
const sortedPlugins = plugins.map((plugin) => ({ | ||
...plugin, | ||
audits: plugin.audits.sort(compareAudits).map((audit) => ({ | ||
...audit, | ||
details: { | ||
...audit.details, | ||
issues: audit?.details?.issues.slice().sort(compareIssues) || [] | ||
} | ||
})) | ||
})); | ||
return { | ||
...report, | ||
categories: sortedCategories, | ||
plugins: sortedPlugins | ||
}; | ||
} | ||
// packages/core/src/lib/implementation/persist.ts | ||
@@ -1486,4 +1531,4 @@ var PersistDirError = class extends Error { | ||
const { outputDir, filename, format } = options; | ||
const scoredReport = scoreReport(report); | ||
console.info(reportToStdout(scoredReport)); | ||
const sortedScoredReport = sortReport(scoreReport(report)); | ||
console.info(reportToStdout(sortedScoredReport)); | ||
const results = []; | ||
@@ -1501,3 +1546,3 @@ if (format.includes("json")) { | ||
format: "md", | ||
content: reportToMd(scoredReport, commitData) | ||
content: reportToMd(sortedScoredReport, commitData) | ||
}); | ||
@@ -1647,3 +1692,3 @@ } | ||
var name = "@code-pushup/core"; | ||
var version = "0.8.9"; | ||
var version = "0.8.10"; | ||
@@ -1650,0 +1695,0 @@ // packages/core/src/lib/implementation/collect.ts |
{ | ||
"name": "@code-pushup/core", | ||
"version": "0.8.9", | ||
"version": "0.8.10", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "@code-pushup/models": "*", |
78660
2011