Skip to content

Commit 2143f3d

Browse files
Copilottadelesh
andauthored
Fix 404 links to rule pages in tspd-generated linter reference (#10501)
Auto-generated linter reference pages (e.g. <a href="https://typespec.io/docs/libraries/http/reference/linter">`/docs/libraries/http/reference/linter`</a>) contained broken links to individual rule pages. ### Root cause `linterRuleLink` in tspd's Starlight (and Docusaurus) emitters stripped the package's `docusaurusWebsite` prefix from each rule URL and appended `.md`, producing browser-absolute paths like `/libraries/http/rules/op-reference-container-route.md`. Because typespec.io is served under a `/docs/` base path, those links resolve to `https://typespec.io/libraries/...` and 404. ### Changes - **`packages/tspd/src/ref-doc/emitters/{starlight,docusaurus}.ts`** — `linterRuleLink` now takes the `LinterRuleRefDoc` (instead of a URL string) and the Starlight/Docusaurus emitters simply return `../rules/${rule.rule.name}.md`. tspd owns the folder structure for generated rule pages, so the filename can be resolved directly without parsing URLs or relying on package metadata. Both Astro/Starlight (via `rehypeAstroRelativeMarkdownLinks`) and Docusaurus rewrite relative `.md` links into proper site URLs honoring the active base path / host, so links work in production, local dev, and PR previews. The `markdown.ts` emitter logic is unchanged. - **`website/.../http/reference/linter.md`** — regenerated via `pnpm regen-docs`; the table cell now links to `../rules/op-reference-container-route.md`. - **Changelog** — added a `fix` entry for `@typespec/tspd`. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tadelesh <1726438+tadelesh@users.noreply.github.com> Co-authored-by: Chenjie Shi <tadelesh.shi@live.cn>
1 parent c3d1f00 commit 2143f3d

5 files changed

Lines changed: 20 additions & 22 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@typespec/tspd"
5+
---
6+
7+
Fix broken (404) links to linter rule pages on auto-generated linter reference pages. The links no longer drop the website base path.

packages/tspd/src/ref-doc/emitters/docusaurus.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
DeprecationNotice,
3+
LinterRuleRefDoc,
34
NamedTypeRefDoc,
45
RefDocEntity,
56
TypeSpecLibraryRefDoc,
@@ -286,14 +287,8 @@ export class DocusaurusRenderer extends MarkdownRenderer {
286287
}
287288
}
288289

289-
linterRuleLink(url: string) {
290-
const homepage = (this.refDoc.packageJson as any).docusaurusWebsite;
291-
if (homepage && url.includes(homepage)) {
292-
const fromRoot = url.replace(homepage, "");
293-
return `${fromRoot}.md`;
294-
} else {
295-
return url;
296-
}
290+
linterRuleLink(rule: LinterRuleRefDoc) {
291+
return `../rules/${rule.rule.name}.md`;
297292
}
298293

299294
deprecationNotice(notice: DeprecationNotice): MarkdownDoc {

packages/tspd/src/ref-doc/emitters/markdown.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,14 @@ export class MarkdownRenderer {
438438
["Name", "Description"],
439439
...rules.map((rule) => {
440440
const name = inlinecode(rule.name);
441-
const nameCell = rule.rule.url ? link(name, this.linterRuleLink(rule.rule.url)) : name;
441+
const ruleLink = this.linterRuleLink(rule);
442+
const nameCell = ruleLink ? link(name, ruleLink) : name;
442443
return [nameCell, rule.rule.description];
443444
}),
444445
]);
445446
}
446447

447-
linterRuleLink(url: string) {
448-
return url;
448+
linterRuleLink(rule: LinterRuleRefDoc): string | undefined {
449+
return rule.rule.url;
449450
}
450451
}

packages/tspd/src/ref-doc/emitters/starlight.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
DeprecationNotice,
3+
LinterRuleRefDoc,
34
NamedTypeRefDoc,
45
RefDocEntity,
56
TypeSpecLibraryRefDoc,
@@ -311,14 +312,8 @@ export class StarlightRenderer extends MarkdownRenderer {
311312
}
312313
}
313314

314-
linterRuleLink(url: string) {
315-
const homepage = (this.refDoc.packageJson as any).docusaurusWebsite;
316-
if (homepage && url.includes(homepage)) {
317-
const fromRoot = url.replace(homepage, "");
318-
return `${fromRoot}.md`;
319-
} else {
320-
return url;
321-
}
315+
linterRuleLink(rule: LinterRuleRefDoc) {
316+
return `../rules/${rule.rule.name}.md`;
322317
}
323318

324319
deprecationNotice(notice: DeprecationNotice): MarkdownDoc {

website/src/content/docs/docs/libraries/http/reference/linter.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Available ruleSets:
2020

2121
## Rules
2222

23-
| Name | Description |
24-
| ------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
25-
| [`@typespec/http/op-reference-container-route`](/libraries/http/rules/op-reference-container-route.md) | Check for referenced (`op is`) operations which have a @route on one of their containers. |
23+
| Name | Description |
24+
| ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
25+
| [`@typespec/http/op-reference-container-route`](../rules/op-reference-container-route.md) | Check for referenced (`op is`) operations which have a @route on one of their containers. |

0 commit comments

Comments
 (0)