Skip to content

Commit defe552

Browse files
authored
feat: report replacement with docs (#20)
* feat: report with docs * update
1 parent a9efcd0 commit defe552

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/providers/diagnostics/rules/replacement.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@ import type { DiagnosticRule } from '..'
33
import { getReplacement } from '#utils/api/replacement'
44
import { DiagnosticSeverity } from 'vscode'
55

6+
function getMdnUrl(path: string): string {
7+
return `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/${path}`
8+
}
9+
10+
function getReplacementsDocUrl(path: string): string {
11+
return `https://github.com/es-tooling/module-replacements/blob/main/docs/modules/${path}.md`
12+
}
13+
614
// https://github.com/npmx-dev/npmx.dev/blob/main/app/components/PackageReplacement.vue#L8-L30
715
function generateMessage(replacement: ModuleReplacement) {
816
switch (replacement.type) {
917
case 'native':
10-
return `This can be replaced with ${replacement.replacement}, available since Node ${replacement.nodeVersion}.`
18+
return `This can be replaced with ${replacement.replacement}, available since Node ${replacement.nodeVersion}. Read more here: ${getMdnUrl(replacement.mdnPath)}`
1119
case 'simple':
1220
return `The community has flagged this package as redundant, with the advice: ${replacement.replacement}.`
1321
case 'documented':
14-
return 'The community has flagged this package as having more performant alternatives.'
22+
return `The community has flagged this package as having more performant alternatives. Read more here: ${getReplacementsDocUrl(replacement.docPath)}`
1523
case 'none':
1624
return 'This package has been flagged as no longer needed, and its functionality is likely available natively in all engines.'
1725
}

0 commit comments

Comments
 (0)