Skip to content

Commit 42c713e

Browse files
committed
feat(valid-types): check link and tutorial for content; #233
1 parent 4afc8e6 commit 42c713e

File tree

4 files changed

+105
-1
lines changed

4 files changed

+105
-1
lines changed

docs/rules/valid-types.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,21 @@ function quux (items) {
487487
}
488488
// Settings: {"jsdoc":{"mode":"typescript"}}
489489
// Message: Syntax error in type: JsdocTypeNullable
490+
491+
/**
492+
* An inline {@link} tag without content.
493+
*/
494+
// Message: Inline tag "link" missing content
495+
496+
/**
497+
* An inline {@tutorial} tag without content.
498+
*/
499+
// Message: Inline tag "tutorial" missing content
500+
501+
/**
502+
* @param {SomeType} aName An inline {@link} tag without content.
503+
*/
504+
// Message: Inline tag "link" missing content
490505
````
491506

492507

@@ -850,5 +865,17 @@ function quux() {
850865
/**
851866
* @returns {Promise<{publicKey, privateKey}>} - The public and private key
852867
*/
868+
869+
/**
870+
* Some other {@inline} tag.
871+
*/
872+
873+
/**
874+
* @param {SomeType} aName An inline {@link text} tag with content.
875+
*/
876+
877+
/**
878+
* An inline {@link text} tag with content.
879+
*/
853880
````
854881

src/jsdocUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ const hasParams = (functionNode) => {
483483

484484
/**
485485
* Gets all names of the target type, including those that refer to a path, e.g.
486-
* "@param foo; @param foo.bar".
486+
* `foo` or `foo.bar`.
487487
* @param {import('comment-parser').Block} jsdoc
488488
* @param {string} targetTagName
489489
* @returns {{

src/rules/validTypes.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import {
55
tryParse,
66
} from '@es-joy/jsdoccomment';
77

8+
const inlineTags = new Set([
9+
'link', 'linkcode', 'linkplain',
10+
'tutorial',
11+
]);
12+
813
const asExpression = /as\s+/u;
914

1015
const suppressTypes = new Set([
@@ -327,6 +332,18 @@ export default iterateJsdoc(({
327332
validNamepathParsing(tag.name, tag.tag);
328333
}
329334
}
335+
336+
for (const inlineTag of tag.inlineTags) {
337+
if (inlineTags.has(inlineTag.tag) && !inlineTag.text && !inlineTag.namepathOrURL) {
338+
report(`Inline tag "${inlineTag.tag}" missing content`, null, tag);
339+
}
340+
}
341+
}
342+
343+
for (const inlineTag of jsdoc.inlineTags) {
344+
if (inlineTags.has(inlineTag.tag) && !inlineTag.text && !inlineTag.namepathOrURL) {
345+
report(`Inline tag "${inlineTag.tag}" missing content`);
346+
}
330347
}
331348
}, {
332349
iterateAllJsdocs: true,

test/rules/assertions/validTypes.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,45 @@ export default {
11021102
},
11031103
},
11041104
},
1105+
{
1106+
code: `
1107+
/**
1108+
* An inline {@link} tag without content.
1109+
*/
1110+
`,
1111+
errors: [
1112+
{
1113+
line: 2,
1114+
message: 'Inline tag "link" missing content',
1115+
},
1116+
],
1117+
},
1118+
{
1119+
code: `
1120+
/**
1121+
* An inline {@tutorial} tag without content.
1122+
*/
1123+
`,
1124+
errors: [
1125+
{
1126+
line: 2,
1127+
message: 'Inline tag "tutorial" missing content',
1128+
},
1129+
],
1130+
},
1131+
{
1132+
code: `
1133+
/**
1134+
* @param {SomeType} aName An inline {@link} tag without content.
1135+
*/
1136+
`,
1137+
errors: [
1138+
{
1139+
line: 3,
1140+
message: 'Inline tag "link" missing content',
1141+
},
1142+
],
1143+
},
11051144
],
11061145
valid: [
11071146
{
@@ -1790,5 +1829,26 @@ export default {
17901829
*/
17911830
`,
17921831
},
1832+
{
1833+
code: `
1834+
/**
1835+
* Some other {@inline} tag.
1836+
*/
1837+
`,
1838+
},
1839+
{
1840+
code: `
1841+
/**
1842+
* @param {SomeType} aName An inline {@link text} tag with content.
1843+
*/
1844+
`,
1845+
},
1846+
{
1847+
code: `
1848+
/**
1849+
* An inline {@link text} tag with content.
1850+
*/
1851+
`,
1852+
},
17931853
],
17941854
};

0 commit comments

Comments
 (0)