Skip to content

Commit 9a55cf1

Browse files
l1bbcsgbrettz9
authored andcommitted
Allow GCC templates in no-undefined-types
1 parent 5b7da11 commit 9a55cf1

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

src/iterateJsdoc.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,23 @@ const curryUtils = (
189189
return false;
190190
};
191191

192-
utils.classHasTag = (tagName) => {
192+
utils.getClassJsdoc = () => {
193193
const classNode = utils.getClassNode();
194194
const classJsdocNode = getJSDocComment(sourceCode, classNode);
195195

196196
if (classJsdocNode) {
197197
const indent = _.repeat(' ', classJsdocNode.loc.start.column);
198-
const classJsdoc = parseComment(classJsdocNode, indent);
199198

200-
if (jsdocUtils.hasTag(classJsdoc, tagName)) {
201-
return true;
202-
}
199+
return parseComment(classJsdocNode, indent);
203200
}
204201

205-
return false;
202+
return null;
203+
};
204+
205+
utils.classHasTag = (tagName) => {
206+
const classJsdoc = utils.getClassJsdoc();
207+
208+
return classJsdoc && jsdocUtils.hasTag(classJsdoc, tagName);
206209
};
207210

208211
utils.forEachTag = (tagName, arrayHandler) => {

src/rules/noUndefinedTypes.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ export default iterateJsdoc(({
6767
})
6868
.value();
6969

70+
let closureGenericTypes = [];
71+
const classJsdoc = utils.getClassJsdoc();
72+
if (classJsdoc && classJsdoc.tags) {
73+
closureGenericTypes = classJsdoc.tags
74+
.filter((tag) => {
75+
return tag.tag === 'template';
76+
})
77+
.map((tag) => {
78+
return tag.name;
79+
});
80+
}
81+
7082
const allDefinedTypes = globalScope.variables.map((variable) => {
7183
return variable.name;
7284
})
@@ -89,7 +101,8 @@ export default iterateJsdoc(({
89101
.concat(extraTypes)
90102
.concat(typedefDeclarations)
91103
.concat(definedTypes)
92-
.concat(definedPreferredTypes);
104+
.concat(definedPreferredTypes)
105+
.concat(closureGenericTypes);
93106

94107
const jsdocTags = utils.filterTags((tag) => {
95108
return utils.isTagWithType(tag.tag);

test/rules/assertions/noUndefinedTypes.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,20 @@ export default {
393393
}
394394
}
395395
}
396+
},
397+
{
398+
code: `
399+
/**
400+
* @template TEMPLATE_TYPE
401+
*/
402+
class Foo {
403+
/**
404+
* @return {TEMPLATE_TYPE}
405+
*/
406+
bar () {
407+
}
408+
}
409+
`
396410
}
397411
]
398412
};

0 commit comments

Comments
 (0)