(report: ScoredReport)
| 90 | } |
| 91 | |
| 92 | export 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 |
| 139 | function sortPlugins( |
no test coverage detected