Skip to content

Commit 74cb57e

Browse files
committed
feat(utils): sort changed categories/groups/audits by most affected
1 parent 0cdcb9e commit 74cb57e

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

packages/utils/src/lib/reports/__snapshots__/report-diff-improved.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
|🏷️ Category|⭐ Current score|⭐ Previous score|🗠 Score change|
88
|:--|:--:|:--:|:--:|
9-
|Performance|🟢 **94**|🟢 92|<span style="color: green">▲ **+2**</span>|
10-
|Bug prevention|🟢 **95**|🟡 68|<span style="color: green">▲ **+27**</span>|
119
|Code style|🟢 **100**|🟡 54|<span style="color: green">▲ **+46**</span>|
10+
|Bug prevention|🟢 **95**|🟡 68|<span style="color: green">▲ **+27**</span>|
11+
|Performance|🟢 **94**|🟢 92|<span style="color: green">▲ **+2**</span>|
1212

1313
## 🎗️ Groups
1414

@@ -30,17 +30,17 @@
3030

3131
|🔌 Plugin|🛡️ Audit|📏 Current value|📏 Previous value|🗠 Value change|
3232
|:--|:--|:--:|:--:|:--:|
33+
|ESLint|Disallow variable declarations from shadowing variables declared in the outer scope|🟩 **passed**|🟥 3 warnings|<span style="color: green">▼ **-100%**</span>|
34+
|ESLint|Require or disallow method and property shorthand syntax for object literals|🟩 **passed**|🟥 3 warnings|<span style="color: green">▼ **-100%**</span>|
35+
|ESLint|verifies the list of dependencies for Hooks like useEffect and similar|🟩 **passed**|🟥 2 warnings|<span style="color: green">▼ **-100%**</span>|
3336
|ESLint|Disallow unused variables|🟩 **passed**|🟥 1 warning|<span style="color: green">▼ **-100%**</span>|
3437
|ESLint|Require braces around arrow function bodies|🟩 **passed**|🟥 1 warning|<span style="color: green">▼ **-100%**</span>|
3538
|ESLint|Require the use of `===` and `!==`|🟩 **passed**|🟥 1 warning|<span style="color: green">▼ **-100%**</span>|
3639
|ESLint|Enforce a maximum number of lines of code in a function|🟩 **passed**|🟥 1 warning|<span style="color: green">▼ **-100%**</span>|
37-
|ESLint|Disallow variable declarations from shadowing variables declared in the outer scope|🟩 **passed**|🟥 3 warnings|<span style="color: green">▼ **-100%**</span>|
38-
|ESLint|Require or disallow method and property shorthand syntax for object literals|🟩 **passed**|🟥 3 warnings|<span style="color: green">▼ **-100%**</span>|
3940
|ESLint|Require `const` declarations for variables that are never reassigned after declared|🟩 **passed**|🟥 1 warning|<span style="color: green">▼ **-100%**</span>|
4041
|ESLint|Disallow missing `key` props in iterators/collection literals|🟩 **passed**|🟥 1 warning|<span style="color: green">▼ **-100%**</span>|
41-
|ESLint|verifies the list of dependencies for Hooks like useEffect and similar|🟩 **passed**|🟥 2 warnings|<span style="color: green">▼ **-100%**</span>|
42-
|Lighthouse|First Contentful Paint|🟨 **1.1 s**|🟨 1.2 s|<span style="color: green">▼ **-4%**</span>|
4342
|Lighthouse|Largest Contentful Paint|🟨 **1.4 s**|🟨 1.5 s|<span style="color: green">▼ **-8%**</span>|
43+
|Lighthouse|First Contentful Paint|🟨 **1.1 s**|🟨 1.2 s|<span style="color: green">▼ **-4%**</span>|
4444
|Lighthouse|Speed Index|🟩 **1.1 s**|🟩 1.2 s|<span style="color: green">▼ **-4%**</span>|
4545

4646
40 other audits are unchanged.

packages/utils/src/lib/reports/__snapshots__/report-diff-mixed.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
|🏷️ Category|⭐ Current score|⭐ Previous score|🗠 Score change|
88
|:--|:--:|:--:|:--:|
9-
|Performance|🟢 **94**|🟢 92|<span style="color: green">▲ **+2**</span>|
109
|Bug prevention|🟡 **63**|🟡 68|<span style="color: red">▼ **-5**</span>|
10+
|Performance|🟢 **94**|🟢 92|<span style="color: green">▲ **+2**</span>|
1111

1212
<details>
1313
<summary>1 other category is unchanged.</summary>
@@ -39,8 +39,8 @@
3939
|🔌 Plugin|🛡️ Audit|📏 Current value|📏 Previous value|🗠 Value change|
4040
|:--|:--|:--:|:--:|:--:|
4141
|ESLint|Disallow unused variables|🟥 **1 error**|🟩 passed|<span style="color: red">▲ **+∞%**</span>|
42-
|Lighthouse|First Contentful Paint|🟨 **1.1 s**|🟨 1.2 s|<span style="color: green">▼ **-4%**</span>|
4342
|Lighthouse|Largest Contentful Paint|🟨 **1.4 s**|🟨 1.5 s|<span style="color: green">▼ **-8%**</span>|
43+
|Lighthouse|First Contentful Paint|🟨 **1.1 s**|🟨 1.2 s|<span style="color: green">▼ **-4%**</span>|
4444
|Lighthouse|Speed Index|🟩 **1.1 s**|🟩 1.2 s|<span style="color: green">▼ **-4%**</span>|
4545

4646
48 other audits are unchanged.

packages/utils/src/lib/reports/generate-md-reports-diff.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function formatDiffCategoriesSection(diff: ReportsDiff): string {
8080
'⭐ Previous score',
8181
'🗠 Score change',
8282
],
83-
...changed.map(category => [
83+
...sortChanges(changed).map(category => [
8484
category.title,
8585
formatScoreWithColor(category.scores.after),
8686
formatScoreWithColor(category.scores.before, { skipBold: true }),
@@ -115,7 +115,7 @@ function formatDiffGroupsSection(diff: ReportsDiff): string {
115115
'⭐ Previous score',
116116
'🗠 Score change',
117117
],
118-
rows: diff.groups.changed.map(group => [
118+
rows: sortChanges(diff.groups.changed).map(group => [
119119
group.plugin.title,
120120
group.title,
121121
formatScoreWithColor(group.scores.after),
@@ -138,7 +138,7 @@ function formatDiffAuditsSection(diff: ReportsDiff): string {
138138
'📏 Previous value',
139139
'🗠 Value change',
140140
],
141-
rows: diff.audits.changed.map(audit => [
141+
rows: sortChanges(diff.audits.changed).map(audit => [
142142
audit.plugin.title,
143143
audit.title,
144144
`${getSquaredScoreMarker(audit.scores.after)} ${style(
@@ -238,9 +238,20 @@ function summarizeDiffOutcomes(outcomes: DiffOutcome[], token: string): string {
238238
.join(', ');
239239
}
240240

241-
function changesToDiffOutcomes(
242-
changes: { scores: { diff: number }; values?: { diff: number } }[],
243-
): DiffOutcome[] {
241+
type Change = {
242+
scores: { diff: number };
243+
values?: { diff: number };
244+
};
245+
246+
function sortChanges<T extends Change>(changes: T[]): T[] {
247+
return [...changes].sort(
248+
(a, b) =>
249+
Math.abs(b.scores.diff) - Math.abs(a.scores.diff) ||
250+
Math.abs(b.values?.diff ?? 0) - Math.abs(a.values?.diff ?? 0),
251+
);
252+
}
253+
254+
function changesToDiffOutcomes(changes: Change[]): DiffOutcome[] {
244255
return changes.map((change): DiffOutcome => {
245256
if (change.scores.diff > 0) {
246257
return 'positive';

0 commit comments

Comments
 (0)