Skip to content

Commit 65e48a6

Browse files
committed
Allow GCC templates in no-undefined-types
1 parent ed08e74 commit 65e48a6

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
@@ -193,20 +193,23 @@ const curryUtils = (
193193
return false;
194194
};
195195

196-
utils.classHasTag = (tagName) => {
196+
utils.getClassJsdoc = () => {
197197
const classNode = utils.getClassNode();
198198
const classJsdocNode = getJSDocComment(sourceCode, classNode);
199199

200200
if (classJsdocNode) {
201201
const indent = _.repeat(' ', classJsdocNode.loc.start.column);
202-
const classJsdoc = parseComment(classJsdocNode, indent);
203202

204-
if (jsdocUtils.hasTag(classJsdoc, tagName)) {
205-
return true;
206-
}
203+
return parseComment(classJsdocNode, indent);
207204
}
208205

209-
return false;
206+
return null;
207+
};
208+
209+
utils.classHasTag = (tagName) => {
210+
const classJsdoc = utils.getClassJsdoc();
211+
212+
return classJsdoc && jsdocUtils.hasTag(classJsdoc, tagName);
210213
};
211214

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

src/rules/noUndefinedTypes.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ export default iterateJsdoc(({
6060
})
6161
.value();
6262

63+
let closureGenericTypes = [];
64+
const classJsdoc = utils.getClassJsdoc();
65+
if (classJsdoc && classJsdoc.tags) {
66+
closureGenericTypes = classJsdoc.tags
67+
.filter((tag) => {
68+
return tag.tag === 'template';
69+
})
70+
.map((tag) => {
71+
return tag.name;
72+
});
73+
}
74+
6375
const allDefinedTypes = globalScope.variables.map((variable) => {
6476
return variable.name;
6577
})
@@ -82,7 +94,8 @@ export default iterateJsdoc(({
8294
.concat(extraTypes)
8395
.concat(typedefDeclarations)
8496
.concat(definedTypes)
85-
.concat(definedPreferredTypes);
97+
.concat(definedPreferredTypes)
98+
.concat(closureGenericTypes);
8699

87100
const jsdocTags = utils.filterTags((tag) => {
88101
return utils.isTagWithType(tag.tag);

test/rules/assertions/noUndefinedTypes.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,20 @@ export default {
326326
}
327327
}
328328
}
329+
},
330+
{
331+
code: `
332+
/**
333+
* @template TEMPLATE_TYPE
334+
*/
335+
class Foo {
336+
/**
337+
* @return {TEMPLATE_TYPE}
338+
*/
339+
bar () {
340+
}
341+
}
342+
`
329343
}
330344
]
331345
};

0 commit comments

Comments
 (0)