Skip to content

Commit 4a8c678

Browse files
committed
feat(utils): format titles as links if docsUrl available in report-diff.md
1 parent 605f964 commit 4a8c678

File tree

5 files changed

+53
-31
lines changed

5 files changed

+53
-31
lines changed

e2e/cli-e2e/tests/__snapshots__/compare.report-diff.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
|🔌 Plugin|🗃️ Group|⭐ Current score|⭐ Previous score|🔄 Score change|
1818
|:--|:--|:--:|:--:|:--:|
19-
|ESLint|Suggestions|🟡 **71**|🟡 50|![↑ +21.4](https://img.shields.io/badge/%E2%86%91%20%2B21.4-green)|
19+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|Suggestions|🟡 **71**|🟡 50|![↑ +21.4](https://img.shields.io/badge/%E2%86%91%20%2B21.4-green)|
2020

2121
3 other groups are unchanged.
2222

@@ -30,9 +30,9 @@
3030

3131
|🔌 Plugin|🛡️ Audit|📏 Current value|📏 Previous value|🔄 Value change|
3232
|:--|:--|:--:|:--:|:--:|
33-
|ESLint|Require or disallow method and property shorthand syntax for object literals|🟩 **passed**|🟥 3 warnings|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
34-
|ESLint|Require braces around arrow function bodies|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
35-
|ESLint|Require `const` declarations for variables that are never reassigned after declared|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
33+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Require or disallow method and property shorthand syntax for object literals](https://eslint.org/docs/latest/rules/object-shorthand)|🟩 **passed**|🟥 3 warnings|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
34+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Require braces around arrow function bodies](https://eslint.org/docs/latest/rules/arrow-body-style)|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
35+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Require `const` declarations for variables that are never reassigned after declared](https://eslint.org/docs/latest/rules/prefer-const)|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
3636

3737
44 other audits are unchanged.
3838

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ All of 1 group is unchanged.
2323

2424
|🔌 Plugin|🛡️ Audit|📏 Current value|📏 Previous value|🔄 Value change|
2525
|:--|:--|:--:|:--:|:--:|
26-
|ESLint|Disallow unused variables|🟥 **1 error**|🟩 passed|![↑ +∞ %](https://img.shields.io/badge/%E2%86%91%20%2B%E2%88%9E%E2%80%89%25-red)|
26+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Disallow unused variables](https://eslint.org/docs/latest/rules/no-unused-vars)|🟥 **1 error**|🟩 passed|![↑ +∞ %](https://img.shields.io/badge/%E2%86%91%20%2B%E2%88%9E%E2%80%89%25-red)|
2727

2828
48 other audits are unchanged.
2929

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
|:--|:--:|:--:|:--:|
99
|Code style|🟢 **100**|🟡 54|![↑ +46](https://img.shields.io/badge/%E2%86%91%20%2B46-green)|
1010
|Bug prevention|🟢 **95**|🟡 68|![↑ +27](https://img.shields.io/badge/%E2%86%91%20%2B27-green)|
11-
|Performance|🟢 **94**|🟢 92|![↑ +2](https://img.shields.io/badge/%E2%86%91%20%2B2-green)|
11+
|[Performance](https://developers.google.com/web/fundamentals/performance)|🟢 **94**|🟢 92|![↑ +2](https://img.shields.io/badge/%E2%86%91%20%2B2-green)|
1212

1313
## 🗃️ Groups
1414

@@ -17,7 +17,7 @@
1717

1818
|🔌 Plugin|🗃️ Group|⭐ Current score|⭐ Previous score|🔄 Score change|
1919
|:--|:--|:--:|:--:|:--:|
20-
|ESLint|Maximum lines limitation|🟢 **100**|🟡 50|![↑ +50](https://img.shields.io/badge/%E2%86%91%20%2B50-green)|
20+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|Maximum lines limitation|🟢 **100**|🟡 50|![↑ +50](https://img.shields.io/badge/%E2%86%91%20%2B50-green)|
2121
|Lighthouse|Performance|🟢 **94**|🟢 92|![↑ +2](https://img.shields.io/badge/%E2%86%91%20%2B2-green)|
2222

2323
</details>
@@ -30,18 +30,18 @@
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|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
34-
|ESLint|Require or disallow method and property shorthand syntax for object literals|🟩 **passed**|🟥 3 warnings|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
35-
|ESLint|verifies the list of dependencies for Hooks like useEffect and similar|🟩 **passed**|🟥 2 warnings|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
36-
|ESLint|Disallow unused variables|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
37-
|ESLint|Require braces around arrow function bodies|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
38-
|ESLint|Require the use of `===` and `!==`|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
39-
|ESLint|Enforce a maximum number of lines of code in a function|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
40-
|ESLint|Require `const` declarations for variables that are never reassigned after declared|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
41-
|ESLint|Disallow missing `key` props in iterators/collection literals|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
42-
|Lighthouse|Largest Contentful Paint|🟨 **1.4 s**|🟨 1.5 s|![↓ −8 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%928%E2%80%89%25-green)|
43-
|Lighthouse|First Contentful Paint|🟨 **1.1 s**|🟨 1.2 s|![↓ −4 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%924%E2%80%89%25-green)|
44-
|Lighthouse|Speed Index|🟩 **1.1 s**|🟩 1.2 s|![↓ −4 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%924%E2%80%89%25-green)|
33+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Disallow variable declarations from shadowing variables declared in the outer scope](https://eslint.org/docs/latest/rules/no-shadow)|🟩 **passed**|🟥 3 warnings|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
34+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Require or disallow method and property shorthand syntax for object literals](https://eslint.org/docs/latest/rules/object-shorthand)|🟩 **passed**|🟥 3 warnings|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
35+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[verifies the list of dependencies for Hooks like useEffect and similar](https://github.com/facebook/react/issues/14920)|🟩 **passed**|🟥 2 warnings|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
36+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Disallow unused variables](https://eslint.org/docs/latest/rules/no-unused-vars)|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
37+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Require braces around arrow function bodies](https://eslint.org/docs/latest/rules/arrow-body-style)|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
38+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Require the use of `===` and `!==`](https://eslint.org/docs/latest/rules/eqeqeq)|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
39+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Enforce a maximum number of lines of code in a function](https://eslint.org/docs/latest/rules/max-lines-per-function)|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
40+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Require `const` declarations for variables that are never reassigned after declared](https://eslint.org/docs/latest/rules/prefer-const)|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
41+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Disallow missing `key` props in iterators/collection literals](https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/jsx-key.md)|🟩 **passed**|🟥 1 warning|![↓ −100 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%92100%E2%80%89%25-green)|
42+
|Lighthouse|[Largest Contentful Paint](https://developer.chrome.com/docs/lighthouse/performance/largest-contentful-paint/)|🟨 **1.4 s**|🟨 1.5 s|![↓ −8 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%928%E2%80%89%25-green)|
43+
|Lighthouse|[First Contentful Paint](https://developer.chrome.com/docs/lighthouse/performance/first-contentful-paint/)|🟨 **1.1 s**|🟨 1.2 s|![↓ −4 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%924%E2%80%89%25-green)|
44+
|Lighthouse|[Speed Index](https://developer.chrome.com/docs/lighthouse/performance/speed-index/)|🟩 **1.1 s**|🟩 1.2 s|![↓ −4 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%924%E2%80%89%25-green)|
4545

4646
40 other audits are unchanged.
4747

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232
|🔌 Plugin|🛡️ Audit|📏 Current value|📏 Previous value|🔄 Value change|
3333
|:--|:--|:--:|:--:|:--:|
34-
|ESLint|Disallow unused variables|🟥 **1 error**|🟩 passed|![↑ +∞ %](https://img.shields.io/badge/%E2%86%91%20%2B%E2%88%9E%E2%80%89%25-red)|
35-
|Lighthouse|Largest Contentful Paint|🟨 **1.4 s**|🟨 1.5 s|![↓ −8 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%928%E2%80%89%25-green)|
36-
|Lighthouse|First Contentful Paint|🟨 **1.1 s**|🟨 1.2 s|![↓ −4 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%924%E2%80%89%25-green)|
37-
|Lighthouse|Speed Index|🟩 **1.1 s**|🟩 1.2 s|![↓ −4 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%924%E2%80%89%25-green)|
34+
|[ESLint](https://www.npmjs.com/package/@code-pushup/eslint-plugin)|[Disallow unused variables](https://eslint.org/docs/latest/rules/no-unused-vars)|🟥 **1 error**|🟩 passed|![↑ +∞ %](https://img.shields.io/badge/%E2%86%91%20%2B%E2%88%9E%E2%80%89%25-red)|
35+
|Lighthouse|[Largest Contentful Paint](https://developer.chrome.com/docs/lighthouse/performance/largest-contentful-paint/)|🟨 **1.4 s**|🟨 1.5 s|![↓ −8 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%928%E2%80%89%25-green)|
36+
|Lighthouse|[First Contentful Paint](https://developer.chrome.com/docs/lighthouse/performance/first-contentful-paint/)|🟨 **1.1 s**|🟨 1.2 s|![↓ −4 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%924%E2%80%89%25-green)|
37+
|Lighthouse|[Speed Index](https://developer.chrome.com/docs/lighthouse/performance/speed-index/)|🟩 **1.1 s**|🟩 1.2 s|![↓ −4 %](https://img.shields.io/badge/%E2%86%93%20%E2%88%924%E2%80%89%25-green)|
3838

3939
48 other audits are unchanged.
4040

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { AuditDiff, ReportsDiff } from '@code-pushup/models';
22
import { pluralize, pluralizeToken } from '../formatting';
33
import { objectToEntries } from '../transform';
4-
import { Alignment, details, h1, h2, paragraphs, style, tableMd } from './md';
4+
import {
5+
Alignment,
6+
details,
7+
h1,
8+
h2,
9+
link,
10+
paragraphs,
11+
style,
12+
tableMd,
13+
} from './md';
514
import { DiffOutcome } from './types';
615
import {
716
colorByScoreDiff,
@@ -73,19 +82,19 @@ function formatDiffCategoriesSection(diff: ReportsDiff): string {
7382
'🔄 Score change',
7483
],
7584
...sortChanges(changed).map(category => [
76-
category.title,
85+
formatTitle(category),
7786
formatScoreWithColor(category.scores.after),
7887
formatScoreWithColor(category.scores.before, { skipBold: true }),
7988
formatScoreChange(category.scores.diff),
8089
]),
8190
...added.map(category => [
82-
category.title,
91+
formatTitle(category),
8392
formatScoreWithColor(category.score),
8493
style('n/a (\\*)', ['i']),
8594
style('n/a (\\*)', ['i']),
8695
]),
8796
...unchanged.map(category => [
88-
category.title,
97+
formatTitle(category),
8998
formatScoreWithColor(category.score),
9099
formatScoreWithColor(category.score, { skipBold: true }),
91100
'–',
@@ -112,8 +121,8 @@ function formatDiffGroupsSection(diff: ReportsDiff): string {
112121
'🔄 Score change',
113122
],
114123
rows: sortChanges(diff.groups.changed).map(group => [
115-
group.plugin.title,
116-
group.title,
124+
formatTitle(group.plugin),
125+
formatTitle(group),
117126
formatScoreWithColor(group.scores.after),
118127
formatScoreWithColor(group.scores.before, { skipBold: true }),
119128
formatScoreChange(group.scores.diff),
@@ -135,8 +144,8 @@ function formatDiffAuditsSection(diff: ReportsDiff): string {
135144
'🔄 Value change',
136145
],
137146
rows: sortChanges(diff.audits.changed).map(audit => [
138-
audit.plugin.title,
139-
audit.title,
147+
formatTitle(audit.plugin),
148+
formatTitle(audit),
140149
`${getSquaredScoreMarker(audit.scores.after)} ${style(
141150
audit.displayValues.after || audit.values.after.toString(),
142151
)}`,
@@ -235,6 +244,19 @@ function summarizeDiffOutcomes(outcomes: DiffOutcome[], token: string): string {
235244
.join(', ');
236245
}
237246

247+
function formatTitle({
248+
title,
249+
docsUrl,
250+
}: {
251+
title: string;
252+
docsUrl?: string;
253+
}): string {
254+
if (docsUrl) {
255+
return link(docsUrl, title);
256+
}
257+
return title;
258+
}
259+
238260
type Change = {
239261
scores: { diff: number };
240262
values?: { diff: number };

0 commit comments

Comments
 (0)