Skip to content

Commit 84f42a0

Browse files
committed
Add support for generic functions in addition to classes
1 parent 84fb449 commit 84f42a0

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/rules/noUndefinedTypes.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,21 @@ export default iterateJsdoc(({
6868
})
6969
.value();
7070

71-
let closureGenericTypes = [];
71+
let templateTags = utils.getPresentTags('template');
7272
const classJsdoc = utils.getClassJsdoc();
7373
if (classJsdoc && classJsdoc.tags) {
74-
closureGenericTypes = classJsdoc.tags
75-
.filter((tag) => {
76-
return tag.tag === 'template';
77-
})
78-
.flatMap((tag) => {
79-
return jsdocUtils.parseClosureTemplateTag(tag);
80-
});
74+
templateTags = templateTags.concat(
75+
classJsdoc.tags
76+
.filter((tag) => {
77+
return tag.tag === 'template';
78+
})
79+
);
8180
}
8281

82+
const closureGenericTypes = templateTags.flatMap((tag) => {
83+
return jsdocUtils.parseClosureTemplateTag(tag);
84+
});
85+
8386
const allDefinedTypes = globalScope.variables.map((variable) => {
8487
return variable.name;
8588
})

test/rules/assertions/noUndefinedTypes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,17 @@ export default {
439439
}
440440
}
441441
},
442+
{
443+
code: `
444+
/**
445+
* @template TEMPLATE_TYPE
446+
* @param {TEMPLATE_TYPE} bar
447+
* @return {TEMPLATE_TYPE}
448+
*/
449+
function foo (bar) {
450+
};
451+
`
452+
},
442453
{
443454
code: `
444455
/**

0 commit comments

Comments
 (0)