Skip to content

Commit

Permalink
feat(valid-types): check link and tutorial for content; #233
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Jun 28, 2023
1 parent 4afc8e6 commit 42c713e
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
27 changes: 27 additions & 0 deletions docs/rules/valid-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,21 @@ function quux (items) {
}
// Settings: {"jsdoc":{"mode":"typescript"}}
// Message: Syntax error in type: JsdocTypeNullable

/**
* An inline {@link} tag without content.
*/
// Message: Inline tag "link" missing content

/**
* An inline {@tutorial} tag without content.
*/
// Message: Inline tag "tutorial" missing content

/**
* @param {SomeType} aName An inline {@link} tag without content.
*/
// Message: Inline tag "link" missing content
````


Expand Down Expand Up @@ -850,5 +865,17 @@ function quux() {
/**
* @returns {Promise<{publicKey, privateKey}>} - The public and private key
*/

/**
* Some other {@inline} tag.
*/

/**
* @param {SomeType} aName An inline {@link text} tag with content.
*/

/**
* An inline {@link text} tag with content.
*/
````

2 changes: 1 addition & 1 deletion src/jsdocUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ const hasParams = (functionNode) => {

/**
* Gets all names of the target type, including those that refer to a path, e.g.
* "@param foo; @param foo.bar".
* `foo` or `foo.bar`.
* @param {import('comment-parser').Block} jsdoc
* @param {string} targetTagName
* @returns {{
Expand Down
17 changes: 17 additions & 0 deletions src/rules/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import {
tryParse,
} from '@es-joy/jsdoccomment';

const inlineTags = new Set([
'link', 'linkcode', 'linkplain',
'tutorial',
]);

const asExpression = /as\s+/u;

const suppressTypes = new Set([
Expand Down Expand Up @@ -327,6 +332,18 @@ export default iterateJsdoc(({
validNamepathParsing(tag.name, tag.tag);
}
}

for (const inlineTag of tag.inlineTags) {
if (inlineTags.has(inlineTag.tag) && !inlineTag.text && !inlineTag.namepathOrURL) {
report(`Inline tag "${inlineTag.tag}" missing content`, null, tag);
}
}
}

for (const inlineTag of jsdoc.inlineTags) {
if (inlineTags.has(inlineTag.tag) && !inlineTag.text && !inlineTag.namepathOrURL) {
report(`Inline tag "${inlineTag.tag}" missing content`);
}
}
}, {
iterateAllJsdocs: true,
Expand Down
60 changes: 60 additions & 0 deletions test/rules/assertions/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,45 @@ export default {
},
},
},
{
code: `
/**
* An inline {@link} tag without content.
*/
`,
errors: [
{
line: 2,
message: 'Inline tag "link" missing content',
},
],
},
{
code: `
/**
* An inline {@tutorial} tag without content.
*/
`,
errors: [
{
line: 2,
message: 'Inline tag "tutorial" missing content',
},
],
},
{
code: `
/**
* @param {SomeType} aName An inline {@link} tag without content.
*/
`,
errors: [
{
line: 3,
message: 'Inline tag "link" missing content',
},
],
},
],
valid: [
{
Expand Down Expand Up @@ -1790,5 +1829,26 @@ export default {
*/
`,
},
{
code: `
/**
* Some other {@inline} tag.
*/
`,
},
{
code: `
/**
* @param {SomeType} aName An inline {@link text} tag with content.
*/
`,
},
{
code: `
/**
* An inline {@link text} tag with content.
*/
`,
},
],
};

0 comments on commit 42c713e

Please sign in to comment.