Skip to content

Commit 761d40c

Browse files
authored
Merge pull request #307 from interfaced/master
feat(no-undefined-types): Handle GCC generic functions
2 parents 88fe68a + 0f15bc6 commit 761d40c

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,6 +3048,14 @@ function quux(foo, bar, baz) {
30483048
// Options: [{"definedTypes":["MyType"],"preferredTypesDefined":true}]
30493049
// Message: The type 'HerType' is undefined.
30503050

3051+
/**
3052+
* @template TEMPLATE_TYPE
3053+
* @param {WRONG_TEMPLATE_TYPE} bar
3054+
*/
3055+
function foo (bar) {
3056+
};
3057+
// Message: The type 'WRONG_TEMPLATE_TYPE' is undefined.
3058+
30513059
class Foo {
30523060
/**
30533061
* @return {TEMPLATE_TYPE}
@@ -3227,6 +3235,14 @@ function quux(foo, bar, baz) {
32273235
// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType<>"},"histype":"HisType.<>"}}}
32283236
// Options: [{"definedTypes":["MyType"],"preferredTypesDefined":true}]
32293237

3238+
/**
3239+
* @template TEMPLATE_TYPE
3240+
* @param {TEMPLATE_TYPE} bar
3241+
* @return {TEMPLATE_TYPE}
3242+
*/
3243+
function foo (bar) {
3244+
};
3245+
32303246
/**
32313247
* @template TEMPLATE_TYPE
32323248
*/

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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ export default {
155155
}
156156
}
157157
},
158+
{
159+
code: `
160+
/**
161+
* @template TEMPLATE_TYPE
162+
* @param {WRONG_TEMPLATE_TYPE} bar
163+
*/
164+
function foo (bar) {
165+
};
166+
`,
167+
errors: [
168+
{
169+
line: 4,
170+
message: 'The type \'WRONG_TEMPLATE_TYPE\' is undefined.'
171+
}
172+
]
173+
},
158174
{
159175
code: `
160176
class Foo {
@@ -439,6 +455,17 @@ export default {
439455
}
440456
}
441457
},
458+
{
459+
code: `
460+
/**
461+
* @template TEMPLATE_TYPE
462+
* @param {TEMPLATE_TYPE} bar
463+
* @return {TEMPLATE_TYPE}
464+
*/
465+
function foo (bar) {
466+
};
467+
`
468+
},
442469
{
443470
code: `
444471
/**

0 commit comments

Comments
 (0)