Skip to content

Commit fa4eff3

Browse files
SkyZeroZxamishne
authored andcommitted
docs(docs-infra): Validate case-sensitive API symbol links in @link
Adds build-time validation for case-sensitive API symbols in `@link`. Avoid broken links (cherry picked from commit d2c7b4e)
1 parent 27da56e commit fa4eff3

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎adev/shared-docs/pipeline/api-gen/rendering/test/transforms/jsdoc-transforms.spec.mts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,23 @@ describe('jsdoc transforms', () => {
199199

200200
expect(entryFn).toThrowError(/Forbidden relative link: cli\/build ng build/);
201201
});
202+
203+
it('should throw on a miscased absolute @link to a known API symbol', () => {
204+
setSymbols({RouterModule: 'router'});
205+
206+
const entryFn = () =>
207+
addHtmlAdditionalLinks({
208+
jsdocTags: [
209+
{
210+
name: 'see',
211+
comment: '{@link /api/router/routerModule#forRoot forRoot}',
212+
},
213+
],
214+
moduleName: 'test',
215+
});
216+
217+
expect(entryFn).toThrowError(/Broken @link.*Did you mean \/api\/router\/RouterModule/);
218+
});
202219
});
203220

204221
describe('addHtmlDescription', () => {

‎adev/shared-docs/pipeline/api-gen/rendering/transforms/jsdoc-transforms.mts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,27 @@ function parseAtLink(link: string): {label: string; url: string} | undefined {
223223
);
224224
}
225225

226+
// Validate absolute `/api/...` links against the known symbol registry. This catches
227+
// miscased symbol names (e.g. `/api/router/routerModule` instead of
228+
// `/api/router/RouterModule`) at build time.
229+
if (rawSymbol.startsWith('/api/')) {
230+
const [pathPart] = rawSymbol.split('#');
231+
const segments = pathPart.split('/').filter((s) => s.length > 0);
232+
const symbolName = segments[segments.length - 1];
233+
// Case-insensitive lookup: find the canonical symbol name in the registry.
234+
const knownSymbols = Object.keys(getSymbolsAsApiEntries());
235+
const canonicalSymbol = knownSymbols.find(
236+
(s) => s.toLowerCase() === symbolName.toLowerCase(),
237+
);
238+
if (canonicalSymbol && canonicalSymbol !== symbolName) {
239+
const expectedUrl = getSymbolUrl(canonicalSymbol);
240+
throw Error(
241+
`Broken @link: ${link}. Did you mean ${expectedUrl}? ` +
242+
`Symbol names in API URLs are case-sensitive.`,
243+
);
244+
}
245+
}
246+
226247
return {
227248
url: rawSymbol,
228249
label: description ?? rawSymbol.split('/').pop()!,

‎packages/router/src/router_config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export interface InMemoryScrollingOptions {
197197
* A set of configuration options for a router module, provided in the
198198
* `forRoot()` method.
199199
*
200-
* @see {@link /api/router/routerModule#forRoot forRoot}
200+
* @see {@link /api/router/RouterModule#forRoot forRoot}
201201
*
202202
*
203203
* @publicApi

0 commit comments

Comments
 (0)