Skip to content

Commit

Permalink
fix(check-types, no-undefined-types, valid-types): In TypeScrip…
Browse files Browse the repository at this point in the history
…t or Closure, add `template` for checking of optional type and namepath

Also:
- prevents preexisting `no-undefined-types` test from failing by ensuring the base type is defined now being checked within `template` is actually defined.
  • Loading branch information
brettz9 committed Jul 12, 2020
1 parent a6f4a4a commit e305cce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -6383,6 +6383,9 @@ function quux () {
}
/**
* @typedef {object} BaseObject
*/
/**
* Run callback when hooked method is called.
*
Expand Down
13 changes: 12 additions & 1 deletion src/jsdocUtils.js
Expand Up @@ -368,8 +368,13 @@ const tagsWithOptionalTypePosition = new Set([
'modifies',
]);

const tagsWithOptionalTypePositionClosure = new Set([
const tagsWithOptionalTypePositionTypescript = new Set([
'template',
...tagsWithOptionalTypePosition,
]);

const tagsWithOptionalTypePositionClosure = new Set([
...tagsWithOptionalTypePositionTypescript,

'export',

Expand All @@ -386,6 +391,10 @@ const tagsWithOptionalTypePositionClosure = new Set([

// None of these show as having curly brackets for their name/namepath
const closureNamepathDefiningTags = new Set([
// Though defines in a sense, it is not parseable in the same way
// for template (e.g., allowing commas)
// 'template',

// These appear to require a "name" in their signature, albeit these
// are somewhat different from other "name"'s (including as described
// at https://jsdoc.app/about-namepaths.html )
Expand Down Expand Up @@ -457,11 +466,13 @@ const tagsWithOptionalNamePosition = new Set([
]);

const typescriptTagsWithOptionalNamePosition = new Set([
'template',
...typescriptNamepathDefiningTags,
...tagsWithOptionalNamePositionBase,
]);

const closureTagsWithOptionalNamePosition = new Set([
'template',
...closureNamepathDefiningTags,
...tagsWithOptionalNamePositionBase,
]);
Expand Down
3 changes: 3 additions & 0 deletions test/rules/assertions/noUndefinedTypes.js
Expand Up @@ -640,6 +640,9 @@ export default {
},
{
code: `
/**
* @typedef {object} BaseObject
*/
/**
* Run callback when hooked method is called.
*
Expand Down

0 comments on commit e305cce

Please sign in to comment.