Skip to content

Commit

Permalink
fix(check-types, no-undefined-types, valid-types): In jsdoc mod…
Browse files Browse the repository at this point in the history
…e, ensure `this` only checked for namepath; in TypeScript or Closure, ensure `this` checked only for type
  • Loading branch information
brettz9 committed Jul 12, 2020
1 parent e305cce commit ef7b294
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/iterateJsdoc.js
Expand Up @@ -272,7 +272,7 @@ const getUtils = (
};

utils.tagMustHaveEitherTypeOrNamePosition = (tagName) => {
return jsdocUtils.tagMustHaveEitherTypeOrNamePosition(tagName);
return jsdocUtils.tagMustHaveEitherTypeOrNamePosition(mode, tagName);
};

utils.tagMightHaveEitherTypeOrNamePosition = (tagName) => {
Expand Down
43 changes: 38 additions & 5 deletions src/jsdocUtils.js
Expand Up @@ -324,9 +324,13 @@ const tagsWithMandatoryTypePosition = new Set([
'type',
]);

const tagsWithMandatoryTypePositionClosure = new Set([
const tagsWithMandatoryTypePositionTypeScript = new Set([
...tagsWithMandatoryTypePosition,
'this',
]);

const tagsWithMandatoryTypePositionClosure = new Set([
...tagsWithMandatoryTypePositionTypeScript,
'define',
]);

Expand Down Expand Up @@ -445,7 +449,6 @@ const tagsWithOptionalNamePositionBase = new Set([
'alias',
'augments', 'extends',
'lends',
'this',

// Signature seems to require a "namepath" (and no counter-examples),
// though it allows an incomplete namepath ending with connecting symbol
Expand All @@ -461,6 +464,9 @@ const tagsWithOptionalNamePositionBase = new Set([
// The following do not seem to allow curly brackets in their doc
// signature or examples (besides `modifies` and `param`)
const tagsWithOptionalNamePosition = new Set([
// Signature seems to require a "namepath" (and no counter-examples)
// Not used with namepath in Closure/TypeScript, however
'this',
...namepathDefiningTags,
...tagsWithOptionalNamePositionBase,
]);
Expand Down Expand Up @@ -500,15 +506,14 @@ const tagsWithMandatoryNamePosition = new Set([
'typedef',
]);

const tagsWithMandatoryTypeOrNamePosition = new Set([
const tagsWithMandatoryTypeOrNamePositionBase = new Set([
// "namepath"
'alias',
'augments', 'extends',
'borrows',
'lends',
'memberof', 'memberof!',
'name',
'this',
'typedef',

'external', 'host',
Expand All @@ -517,6 +522,20 @@ const tagsWithMandatoryTypeOrNamePosition = new Set([
'mixes',
]);

const tagsWithMandatoryTypeOrNamePosition = new Set([
// namepath
'this',
...tagsWithMandatoryTypeOrNamePositionBase,
]);

const tagsWithMandatoryTypeOrNamePositionTypescript = new Set([
...tagsWithMandatoryTypeOrNamePositionBase,
]);

const tagsWithMandatoryTypeOrNamePositionClosure = new Set([
...tagsWithMandatoryTypeOrNamePositionBase,
]);

const isNamepathDefiningTag = (mode, tagName) => {
if (mode === 'closure') {
return closureNamepathDefiningTags.has(tagName);
Expand All @@ -533,6 +552,10 @@ const tagMightHaveTypePosition = (mode, tag) => {
return tagsWithMandatoryTypePositionClosure.has(tag) ||
tagsWithOptionalTypePositionClosure.has(tag);
}
if (mode === 'typescript') {
return tagsWithMandatoryTypePositionTypeScript.has(tag) ||
tagsWithOptionalTypePositionTypescript.has(tag);
}

return tagsWithMandatoryTypePosition.has(tag) ||
tagsWithOptionalTypePosition.has(tag);
Expand All @@ -542,6 +565,9 @@ const tagMustHaveTypePosition = (mode, tag) => {
if (mode === 'closure') {
return tagsWithMandatoryTypePositionClosure.has(tag);
}
if (mode === 'typescript') {
return tagsWithMandatoryTypePositionTypeScript.has(tag);
}

return tagsWithMandatoryTypePosition.has(tag);
};
Expand All @@ -565,7 +591,14 @@ const tagMightHaveEitherTypeOrNamePosition = (mode, tag) => {
return tagMightHaveTypePosition(mode, tag) || tagMightHaveNamePosition(mode, tag);
};

const tagMustHaveEitherTypeOrNamePosition = (tag) => {
const tagMustHaveEitherTypeOrNamePosition = (mode, tag) => {
if (mode === 'closure') {
return tagsWithMandatoryTypeOrNamePositionClosure.has(tag);
}
if (mode === 'typescript') {
return tagsWithMandatoryTypeOrNamePositionTypescript.has(tag);
}

return tagsWithMandatoryTypeOrNamePosition.has(tag);
};

Expand Down

0 comments on commit ef7b294

Please sign in to comment.