Skip to content

Commit 5fbab65

Browse files
authored
fix(check-template-names, require-template): ensure template name is based on what is within any brackets and preceding equal sign; fixes #1466 (#1468)
1 parent d67dc2d commit 5fbab65

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

docs/rules/check-template-names.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,5 +395,21 @@ export class User {
395395
}
396396
methodToIgnore() {}
397397
}
398+
399+
/**
400+
* @template [ChannelDataType=undefined]
401+
* @param {string} messageType - A key used for sending and receiving messages.
402+
* @returns {MessageChannel<ChannelDataType>} A channel that can create messages of its
403+
* own type.
404+
*/
405+
export function createMessageChannel(messageType) {
406+
// Note: It should also infer the type if the new channel is returned
407+
// directly rather than returned as a typed variable.
408+
409+
/** @type {MessageChannel<ChannelDataType>} */
410+
const messageChannel = new MessageChannel(messageType);
411+
412+
return messageChannel;
413+
}
398414
````
399415

src/rules/checkTemplateNames.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ export default iterateJsdoc(({
7070

7171
const checkTemplateTags = () => {
7272
for (const tag of templateTags) {
73-
const {
74-
name,
75-
} = tag;
76-
const names = name.split(/,\s*/v);
73+
const names = utils.parseClosureTemplateTag(tag);
7774
for (const nme of names) {
7875
if (!usedNames.has(nme)) {
7976
report(`@template ${nme} not in use`, null, tag);

src/rules/requireTemplate.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ export default iterateJsdoc(({
3232

3333
if (requireSeparateTemplates) {
3434
for (const tag of templateTags) {
35-
const {
36-
name,
37-
} = tag;
38-
const names = name.split(/,\s*/v);
35+
const names = utils.parseClosureTemplateTag(tag);
3936
if (names.length > 1) {
4037
report(`Missing separate @template for ${names[1]}`, null, tag);
4138
}

test/rules/assertions/checkTemplateNames.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,5 +748,24 @@ export default /** @type {import('../index.js').TestCases} */ ({
748748
}
749749
`,
750750
},
751+
{
752+
code: `
753+
/**
754+
* @template [ChannelDataType=undefined]
755+
* @param {string} messageType - A key used for sending and receiving messages.
756+
* @returns {MessageChannel<ChannelDataType>} A channel that can create messages of its
757+
* own type.
758+
*/
759+
export function createMessageChannel(messageType) {
760+
// Note: It should also infer the type if the new channel is returned
761+
// directly rather than returned as a typed variable.
762+
763+
/** @type {MessageChannel<ChannelDataType>} */
764+
const messageChannel = new MessageChannel(messageType);
765+
766+
return messageChannel;
767+
}
768+
`,
769+
},
751770
],
752771
});

0 commit comments

Comments
 (0)