Skip to content

feat(valid-types): check link and tutorial for content #1121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
*/
`,
},
],
};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"lib": ["es2022"],
"moduleResolution": "node",
"module": "esnext",
"module": "NodeNext",
"allowJs": true,
"checkJs": true,
"noEmit": true,
Expand Down