Skip to content

Commit

Permalink
fix(no-undefined-types): ensure parsing takes into account template…
Browse files Browse the repository at this point in the history
… names with defaults
  • Loading branch information
brettz9 committed May 24, 2022
1 parent 53e4174 commit 374daac
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10367,6 +10367,19 @@ const a = 'string';
*/
const a = new Todo();
// Settings: {"jsdoc":{"mode":"typescript"}}

/**
* @template A, [B=SomeDefault]
*/
class Foo {
/**
* @param {A} baz
* @return {B}
*/
bar (baz) {
}
}
// Settings: {"jsdoc":{"mode":"typescript"}}
````


Expand Down
2 changes: 1 addition & 1 deletion src/jsdocUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ const parseClosureTemplateTag = (tag) => {
return tag.name
.split(',')
.map((type) => {
return type.trim();
return type.trim().replace(/^\[(?<name>.*?)=.*\]$/u, '$<name>');
});
};

Expand Down
20 changes: 20 additions & 0 deletions test/rules/assertions/noUndefinedTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1258,5 +1258,25 @@ export default {
},
},
},
{
code: `
/**
* @template A, [B=SomeDefault]
*/
class Foo {
/**
* @param {A} baz
* @return {B}
*/
bar (baz) {
}
}
`,
settings: {
jsdoc: {
mode: 'typescript',
},
},
},
],
};

0 comments on commit 374daac

Please sign in to comment.