From e305ccedb2e0dd4c0e434f5f7cf9bb753882070f Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sun, 12 Jul 2020 17:10:18 +0800 Subject: [PATCH] fix(`check-types`, `no-undefined-types`, `valid-types`): In TypeScript 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. --- README.md | 3 +++ src/jsdocUtils.js | 13 ++++++++++++- test/rules/assertions/noUndefinedTypes.js | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6317d59dc..582df140a 100644 --- a/README.md +++ b/README.md @@ -6383,6 +6383,9 @@ function quux () { } +/** + * @typedef {object} BaseObject + */ /** * Run callback when hooked method is called. * diff --git a/src/jsdocUtils.js b/src/jsdocUtils.js index b9188116e..68c5fffd8 100644 --- a/src/jsdocUtils.js +++ b/src/jsdocUtils.js @@ -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', @@ -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 ) @@ -457,11 +466,13 @@ const tagsWithOptionalNamePosition = new Set([ ]); const typescriptTagsWithOptionalNamePosition = new Set([ + 'template', ...typescriptNamepathDefiningTags, ...tagsWithOptionalNamePositionBase, ]); const closureTagsWithOptionalNamePosition = new Set([ + 'template', ...closureNamepathDefiningTags, ...tagsWithOptionalNamePositionBase, ]); diff --git a/test/rules/assertions/noUndefinedTypes.js b/test/rules/assertions/noUndefinedTypes.js index 30385851d..2b3048fa6 100644 --- a/test/rules/assertions/noUndefinedTypes.js +++ b/test/rules/assertions/noUndefinedTypes.js @@ -640,6 +640,9 @@ export default { }, { code: ` + /** + * @typedef {object} BaseObject + */ /** * Run callback when hooked method is called. *