MCPcopy Create free account
hub / github.com/code-pushup/cli / sortReport

Function sortReport

packages/utils/src/lib/reports/sorting.ts:92–136  ·  view source on GitHub ↗
(report: ScoredReport)

Source from the content-addressed store, hash-verified

90}
91
92export function sortReport(report: ScoredReport): ScoredReport {
93 const { categories, plugins } = report;
94 const sortedCategories = categories?.map(category => {
95 const { audits, groups } = category.refs.reduce(
96 (
97 acc: {
98 audits: SortableAuditReport[];
99 groups: SortableGroup[];
100 },
101 ref: CategoryRef,
102 ) => ({
103 ...acc,
104 ...(ref.type === 'group'
105 ? {
106 groups: [...acc.groups, getSortableGroupByRef(ref, plugins)],
107 }
108 : {
109 audits: [...acc.audits, getSortableAuditByRef(ref, plugins)],
110 }),
111 }),
112 { groups: [], audits: [] },
113 );
114 const sortedAuditsAndGroups = [...audits, ...groups].sort(
115 compareCategoryAuditsAndGroups,
116 );
117
118 const sortedRefs = category.refs.toSorted((a, b) => {
119 const aIndex = sortedAuditsAndGroups.findIndex(
120 ref => ref.slug === a.slug && ref.plugin === a.plugin,
121 );
122 const bIndex = sortedAuditsAndGroups.findIndex(
123 ref => ref.slug === b.slug && ref.plugin === b.plugin,
124 );
125 return aIndex - bIndex;
126 });
127
128 return { ...category, refs: sortedRefs };
129 });
130
131 return {
132 ...report,
133 categories: sortedCategories,
134 plugins: sortPlugins(plugins),
135 };
136}
137
138// NOTE: Only audits are sorted as groups are only listed within categories, not separately
139function sortPlugins(

Calls 3

getSortableGroupByRefFunction · 0.85
getSortableAuditByRefFunction · 0.85
sortPluginsFunction · 0.85

Tested by

no test coverage detected