Skip to content

Commit 2bd7242

Browse files
authored
fix(valid-types): fix parsing of expressions like @returns {@link SomeType}; fixes #1381 (#1382)
1 parent 1bef636 commit 2bd7242

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

docs/rules/valid-types.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,5 +884,9 @@ function quux() {
884884
/**
885885
* @import { TestOne, TestTwo } from "./types"
886886
*/
887+
888+
/**
889+
* @returns {@link SomeType}
890+
*/
887891
````
888892

src/rules/validTypes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ export default iterateJsdoc(({
291291
continue;
292292
}
293293

294+
// Documentation like `@returns {@link SomeType}` is technically ambiguous. Specifically it
295+
// could either be intepreted as a type `"@link SomeType"` or a description `"{@link SomeType}"`.
296+
// However this is a good heuristic.
297+
if (tag.type.trim().startsWith('@')) {
298+
tag.description = `{${tag.type}} ${tag.description}`;
299+
tag.type = '';
300+
}
301+
294302
const mightHaveTypePosition = utils.tagMightHaveTypePosition(tag.tag, otherModeMaps);
295303
if (mightHaveTypePosition !== true && tag.type) {
296304
const modeInfo = mightHaveTypePosition === false ? '' : ` in "${mode}" mode`;

test/rules/assertions/validTypes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,6 +1859,13 @@ export default /** @type {import('../index.js').TestCases} */ ({
18591859
* @import { TestOne, TestTwo } from "./types"
18601860
*/
18611861
`,
1862+
},
1863+
{
1864+
code: `
1865+
/**
1866+
* @returns {@link SomeType}
1867+
*/
1868+
`,
18621869
}
18631870
],
18641871
});

0 commit comments

Comments
 (0)