Skip to content
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
5 changes: 5 additions & 0 deletions docs/rules/check-tag-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -1157,5 +1157,10 @@ interface WebTwain {
* @param {AnotherType} anotherName And yet {@another}
*/
// "jsdoc/check-tag-names": ["error"|"warn", {"inlineTags":["inline","another","inlineTag","link"]}]

/**
* @typeParam T
*/
// Settings: {"jsdoc":{"tagNamePreference":{"template":"typeParam"}}}
````

6 changes: 6 additions & 0 deletions docs/rules/check-template-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ export default class <NumType> {
* @param {[X, Y | undefined]} someParam
*/
// Message: @template D not in use

/**
* @template
*/
// Settings: {"jsdoc":{"tagNamePreference":{"template":false}}}
// Message: Unexpected tag `@template`
````


Expand Down
19 changes: 19 additions & 0 deletions docs/rules/require-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ function foo<T>(bar: T, baz: number | boolean): T {
return bar;
}
// Message: Missing @template T

/**
* @template
*/
// Settings: {"jsdoc":{"tagNamePreference":{"template":false}}}
// Message: Unexpected tag `@template`
````


Expand Down Expand Up @@ -399,5 +405,18 @@ type Pairs<D, V> = [D, V | undefined];
* @typedef {[D, V | undefined]} Pairs
*/
// "jsdoc/require-template": ["error"|"warn", {"exemptedBy":["inheritdoc"]}]

/**
* Test interface for type definitions.
*
* @typeParam Foo - dummy type param
*/
export interface Test<Foo extends string> {
/**
*
*/
bar: Foo;
}
// Settings: {"jsdoc":{"tagNamePreference":{"template":"typeParam"}}}
````

11 changes: 9 additions & 2 deletions src/rules/checkTemplateNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ export default iterateJsdoc(({
mode,
} = settings;

const templateTags = utils.getTags('template');
const tgName = /** @type {string} */ (utils.getPreferredTagName({
tagName: 'template',
}));
if (!tgName) {
return;
}

const templateTags = utils.getTags(tgName);

const usedNames = new Set();
/**
Expand Down Expand Up @@ -73,7 +80,7 @@ export default iterateJsdoc(({
const names = utils.parseClosureTemplateTag(tag);
for (const nme of names) {
if (!usedNames.has(nme)) {
report(`@template ${nme} not in use`, null, tag);
report(`@${tgName} ${nme} not in use`, null, tag);
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions src/rules/requireTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ export default iterateJsdoc(({
} = settings;

const usedNames = new Set();
const templateTags = utils.getTags('template');

const tgName = /** @type {string} */ (utils.getPreferredTagName({
tagName: 'template',
}));
if (!tgName) {
return;
}

const templateTags = utils.getTags(tgName);

const templateNames = templateTags.flatMap((tag) => {
return utils.parseClosureTemplateTag(tag);
});
Expand All @@ -34,7 +43,7 @@ export default iterateJsdoc(({
for (const tag of templateTags) {
const names = utils.parseClosureTemplateTag(tag);
if (names.length > 1) {
report(`Missing separate @template for ${names[1]}`, null, tag);
report(`Missing separate @${tgName} for ${names[1]}`, null, tag);
}
}
}
Expand Down Expand Up @@ -64,7 +73,7 @@ export default iterateJsdoc(({

for (const usedName of usedNames) {
if (!templateNames.includes(usedName)) {
report(`Missing @template ${usedName}`);
report(`Missing @${tgName} ${usedName}`);
}
}
};
Expand Down Expand Up @@ -156,7 +165,7 @@ export default iterateJsdoc(({
// Could check against whitelist/blacklist
for (const usedName of usedNames) {
if (!templateNames.includes(usedName)) {
report(`Missing @template ${usedName}`, null, usedNameToTag.get(usedName));
report(`Missing @${tgName} ${usedName}`, null, usedNameToTag.get(usedName));
}
}
};
Expand Down
7 changes: 5 additions & 2 deletions src/tagNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,11 @@ const typeScriptTags = {
satisfies: [],

// `@template` is also in TypeScript per:
// https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc
template: [],
// https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#template
template: [
// Alias as per https://typedoc.org/documents/Tags._typeParam.html
'typeParam',
],
};

/**
Expand Down
14 changes: 14 additions & 0 deletions test/rules/assertions/checkTagNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -1499,5 +1499,19 @@ export default /** @type {import('../index.js').TestCases} */ ({
},
],
},
{
code: `
/**
* @typeParam T
*/
`,
settings: {
jsdoc: {
tagNamePreference: {
template: 'typeParam',
},
},
},
},
],
});
20 changes: 20 additions & 0 deletions test/rules/assertions/checkTemplateNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,26 @@ export default /** @type {import('../index.js').TestCases} */ ({
},
],
},
{
code: `
/**
* @template
*/
`,
errors: [
{
line: 3,
message: 'Unexpected tag `@template`',
},
],
settings: {
jsdoc: {
tagNamePreference: {
template: false,
},
},
},
},
],
valid: [
{
Expand Down
45 changes: 45 additions & 0 deletions test/rules/assertions/requireTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,26 @@ export default /** @type {import('../index.js').TestCases} */ ({
parser: typescriptEslintParser,
},
},
{
code: `
/**
* @template
*/
`,
errors: [
{
line: 3,
message: 'Unexpected tag `@template`',
},
],
settings: {
jsdoc: {
tagNamePreference: {
template: false,
},
},
},
},
],
valid: [
{
Expand Down Expand Up @@ -701,5 +721,30 @@ export default /** @type {import('../index.js').TestCases} */ ({
},
],
},
{
code: `
/**
* Test interface for type definitions.
*
* @typeParam Foo - dummy type param
*/
export interface Test<Foo extends string> {
/**
*
*/
bar: Foo;
}
`,
languageOptions: {
parser: typescriptEslintParser,
},
settings: {
jsdoc: {
tagNamePreference: {
template: 'typeParam',
},
},
},
},
],
});
Loading