Skip to content

Commit

Permalink
refactor: rename methods/variables related to type/name checking
Browse files Browse the repository at this point in the history
This change is to reflect that these variables are about conventional position of type vs. name(path) rather than whether they actually represent a type or name(path).
  • Loading branch information
brettz9 committed Dec 1, 2019
1 parent 78f7992 commit 471302a
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8955,7 +8955,7 @@ function quux() {
}
// Options: [{"allowEmptyNamepaths":false}]
// Message: Tag @callback must have a namepath
// Message: Tag @callback must have a name/namepath
/**
* @constant {str%ng}
Expand Down
24 changes: 12 additions & 12 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,28 +198,28 @@ const getUtils = (
return false;
};

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

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

utils.tagMustHaveNamepath = (tagName) => {
return jsdocUtils.tagMustHaveNamepath(tagName);
utils.tagMustHaveNamePosition = (tagName) => {
return jsdocUtils.tagMustHaveNamePosition(tagName);
};

utils.tagMightHaveNamepath = (tagName) => {
return jsdocUtils.tagMightHaveNamepath(tagName);
utils.tagMightHaveNamePosition = (tagName) => {
return jsdocUtils.tagMightHaveNamePosition(tagName);
};

utils.tagMustHaveType = (tagName) => {
return jsdocUtils.tagMustHaveType(tagName);
utils.tagMustHaveTypePosition = (tagName) => {
return jsdocUtils.tagMustHaveTypePosition(tagName);
};

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

utils.isNamepathDefiningTag = (tagName) => {
Expand Down
61 changes: 29 additions & 32 deletions src/jsdocUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,7 @@ const hasDefinedTypeReturnTag = (tag) => {
return true;
};

// Todo: These type and namepath tag listings currently look
// at tags with `{...}` as being a type, but jsdoc may
// allow some namepaths only within brackets as well

const tagsWithMandatoryType = [
const tagsWithMandatoryTypePosition = [
// These both show curly brackets in the doc signature and examples
// "typeExpression"
'implements',
Expand All @@ -192,7 +188,7 @@ const tagsWithMandatoryType = [
// `param`/`arg`/`argument` (no signature)
// `property`/`prop` (no signature)
// `modifies` (undocumented)
const tagsWithOptionalType = [
const tagsWithOptionalTypePosition = [
// These have the example showing curly brackets but not in their doc signature, e.g.: https://jsdoc.app/tags-enum.html
'enum',
'member', 'var',
Expand Down Expand Up @@ -225,8 +221,8 @@ const tagsWithOptionalType = [
'modifies',
];

const tagsWithOptionalTypeClosure = [
...tagsWithOptionalType,
const tagsWithOptionalTypePositionClosure = [
...tagsWithOptionalTypePosition,

// Shows the signature with curly brackets but not in the example
// "typeExpression"
Expand Down Expand Up @@ -257,7 +253,8 @@ const namepathDefiningTags = [
'namespace',

// Todo: Should add `module` here (with optional "name" and no curly brackets);
// this block impacts `no-undefined-types` and `valid-types` (search for "isNamepathDefiningTag|tagMightHaveNamepath|tagMightHaveEitherTypeOrNamepath")
// this block impacts `no-undefined-types` and `valid-types` (search for
// "isNamepathDefiningTag|tagMightHaveNamePosition|tagMightHaveEitherTypeOrNamePosition")

// These seem to all require a "namepath" in their signatures (with no counter-examples)
'name',
Expand All @@ -267,7 +264,7 @@ const namepathDefiningTags = [

// The following do not seem to allow curly brackets in their doc
// signature or examples (besides `modifies`)
const tagsWithOptionalNamepath = [
const tagsWithOptionalNamePosition = [
...namepathDefiningTags,

// `borrows` has a different format, however, so needs special parsing;
Expand Down Expand Up @@ -298,7 +295,7 @@ const tagsWithOptionalNamepath = [
// Todo: `@link` seems to require a namepath OR URL and might be checked as such.

// The doc signature of `event` seems to require a "name"
const tagsWithMandatoryNamepath = [
const tagsWithMandatoryNamePosition = [
// "name" (and a special syntax for the `external` name)
'external', 'host',

Expand All @@ -308,7 +305,7 @@ const tagsWithMandatoryNamepath = [
'typedef',
];

const tagsWithMandatoryTypeOrNamepath = [
const tagsWithMandatoryTypeOrNamePosition = [
// "namepath"
'alias',
'augments', 'extends',
Expand All @@ -330,30 +327,30 @@ const isNamepathDefiningTag = (tagName) => {
return namepathDefiningTags.includes(tagName);
};

const tagMightHaveAType = (mode, tag) => {
return tagsWithMandatoryType.includes(tag) || (mode === 'closure' ?
tagsWithOptionalTypeClosure.includes(tag) :
tagsWithOptionalType.includes(tag));
const tagMightHaveTypePosition = (mode, tag) => {
return tagsWithMandatoryTypePosition.includes(tag) || (mode === 'closure' ?
tagsWithOptionalTypePositionClosure.includes(tag) :
tagsWithOptionalTypePosition.includes(tag));
};

const tagMustHaveType = (tag) => {
return tagsWithMandatoryType.includes(tag);
const tagMustHaveTypePosition = (tag) => {
return tagsWithMandatoryTypePosition.includes(tag);
};

const tagMightHaveNamepath = (tag) => {
return tagsWithOptionalNamepath.includes(tag);
const tagMightHaveNamePosition = (tag) => {
return tagsWithOptionalNamePosition.includes(tag);
};

const tagMustHaveNamepath = (tag) => {
return tagsWithMandatoryNamepath.includes(tag);
const tagMustHaveNamePosition = (tag) => {
return tagsWithMandatoryNamePosition.includes(tag);
};

const tagMightHaveEitherTypeOrNamepath = (mode, tag) => {
return tagMightHaveAType(mode, tag) || tagMightHaveNamepath(tag);
const tagMightHaveEitherTypeOrNamePosition = (mode, tag) => {
return tagMightHaveTypePosition(mode, tag) || tagMightHaveNamePosition(tag);
};

const tagMustHaveEitherTypeOrNamepath = (tag) => {
return tagsWithMandatoryTypeOrNamepath.includes(tag);
const tagMustHaveEitherTypeOrNamePosition = (tag) => {
return tagsWithMandatoryTypeOrNamePosition.includes(tag);
};

/**
Expand Down Expand Up @@ -539,10 +536,10 @@ export default {
isNamepathDefiningTag,
isValidTag,
parseClosureTemplateTag,
tagMightHaveAType,
tagMightHaveEitherTypeOrNamepath,
tagMightHaveNamepath,
tagMustHaveEitherTypeOrNamepath,
tagMustHaveNamepath,
tagMustHaveType,
tagMightHaveEitherTypeOrNamePosition,
tagMightHaveNamePosition,
tagMightHaveTypePosition,
tagMustHaveEitherTypeOrNamePosition,
tagMustHaveNamePosition,
tagMustHaveTypePosition,
};
2 changes: 1 addition & 1 deletion src/rules/checkTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default iterateJsdoc(({
context,
}) => {
const jsdocTagsWithPossibleType = utils.filterTags((tag) => {
return utils.tagMightHaveAType(tag.tag);
return utils.tagMightHaveTypePosition(tag.tag);
});

const {preferredTypes} = settings;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/noUndefinedTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default iterateJsdoc(({
.concat(settings.mode === 'jsdoc' ? [] : closureGenericTypes);

const jsdocTagsWithPossibleType = utils.filterTags((tag) => {
return utils.tagMightHaveAType(tag.tag);
return utils.tagMightHaveTypePosition(tag.tag);
});

jsdocTagsWithPossibleType.forEach((tag) => {
Expand Down
22 changes: 11 additions & 11 deletions src/rules/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ export default iterateJsdoc(({
return true;
};

const hasType = utils.tagMightHaveAType(tag.tag) && Boolean(tag.type);
const mustHaveType = utils.tagMustHaveType(tag.tag);
const hasTypePosition = utils.tagMightHaveTypePosition(tag.tag) && Boolean(tag.type);
const mustHaveTypePosition = utils.tagMustHaveTypePosition(tag.tag);

const hasNamePath = utils.tagMightHaveNamepath(tag.tag) && Boolean(tag.name) && !(tag.tag === 'see' && !checkSeesForNamepaths);
const mustHaveNamepath = utils.tagMustHaveNamepath(tag.tag) && !allowEmptyNamepaths;
const hasNameOrNamepathPosition = utils.tagMightHaveNamePosition(tag.tag) && Boolean(tag.name) && !(tag.tag === 'see' && !checkSeesForNamepaths);
const mustHaveNameOrNamepathPosition = utils.tagMustHaveNamePosition(tag.tag) && !allowEmptyNamepaths;

const hasEither = utils.tagMightHaveEitherTypeOrNamepath(tag.tag) && hasType || hasNamePath;
const mustHaveEither = utils.tagMustHaveEitherTypeOrNamepath(tag.tag);
const hasEither = utils.tagMightHaveEitherTypeOrNamePosition(tag.tag) && hasTypePosition || hasNameOrNamepathPosition;
const mustHaveEither = utils.tagMustHaveEitherTypeOrNamePosition(tag.tag);

if (tag.tag === 'borrows') {
const thisNamepath = tag.description.replace(asExpression, '');
Expand All @@ -103,16 +103,16 @@ export default iterateJsdoc(({
return;
}

if (hasType) {
if (hasTypePosition) {
validTypeParsing(tag.type);
} else if (mustHaveType) {
} else if (mustHaveTypePosition) {
report(`Tag @${tag.tag} must have a type`, null, tag);
}

if (hasNamePath) {
if (hasNameOrNamepathPosition) {
validNamepathParsing(tag.name, tag.tag);
} else if (mustHaveNamepath) {
report(`Tag @${tag.tag} must have a namepath`, null, tag);
} else if (mustHaveNameOrNamepathPosition) {
report(`Tag @${tag.tag} must have a name/namepath`, null, tag);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/rules/assertions/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default {
`,
errors: [{
line: 3,
message: 'Tag @callback must have a namepath',
message: 'Tag @callback must have a name/namepath',
}],
options: [{
allowEmptyNamepaths: false,
Expand Down

0 comments on commit 471302a

Please sign in to comment.