Skip to content

Commit eaf41ed

Browse files
TimvdLippebrettz9
authored andcommitted
fix(no-undefined-types): do not crash on variadic arguments
When running `no-undefined-types` on our codebase, I discovered that it crashes on `variadic` arguments. It turns out that jsdoctypeparser does not cleanly traverse over variadic arguments. Thus, used the `parsedType` to traverse over instead.
1 parent 160e86f commit eaf41ed

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4117,6 +4117,13 @@ class Foo {
41174117
}
41184118
}
41194119
// Message: The type 'TEMPLATE_TYPE_A' is undefined.
4120+
4121+
/**
4122+
* @param {...VAR_TYPE} varargs
4123+
*/
4124+
function quux (varargs) {
4125+
}
4126+
// Message: The type 'VAR_TYPE' is undefined.
41204127
````
41214128

41224129
The following patterns are not considered problems:
@@ -4323,6 +4330,18 @@ function registerEvent(obj, method, callback) {
43234330

43244331
}
43254332
// Settings: {"jsdoc":{"mode":"typescript"}}
4333+
4334+
/**
4335+
* @param {...} varargs
4336+
*/
4337+
function quux (varargs) {
4338+
}
4339+
4340+
/**
4341+
* @param {...number} varargs
4342+
*/
4343+
function quux (varargs) {
4344+
}
43264345
````
43274346

43284347

test/rules/assertions/noUndefinedTypes.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,21 @@ export default {
261261
},
262262
],
263263
},
264+
{
265+
code: `
266+
/**
267+
* @param {...VAR_TYPE} varargs
268+
*/
269+
function quux (varargs) {
270+
}
271+
`,
272+
errors: [
273+
{
274+
line: 3,
275+
message: 'The type \'VAR_TYPE\' is undefined.',
276+
},
277+
],
278+
},
264279
],
265280
valid: [
266281
{
@@ -583,5 +598,23 @@ export default {
583598
},
584599
},
585600
},
601+
{
602+
code: `
603+
/**
604+
* @param {...} varargs
605+
*/
606+
function quux (varargs) {
607+
}
608+
`,
609+
},
610+
{
611+
code: `
612+
/**
613+
* @param {...number} varargs
614+
*/
615+
function quux (varargs) {
616+
}
617+
`,
618+
},
586619
],
587620
};

0 commit comments

Comments
 (0)