Skip to content

Commit 471302a

Browse files
committed
refactor: rename methods/variables related to type/name checking
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).
1 parent 78f7992 commit 471302a

File tree

7 files changed

+56
-59
lines changed

7 files changed

+56
-59
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8955,7 +8955,7 @@ function quux() {
89558955
89568956
}
89578957
// Options: [{"allowEmptyNamepaths":false}]
8958-
// Message: Tag @callback must have a namepath
8958+
// Message: Tag @callback must have a name/namepath
89598959
89608960
/**
89618961
* @constant {str%ng}

src/iterateJsdoc.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,28 +198,28 @@ const getUtils = (
198198
return false;
199199
};
200200

201-
utils.tagMustHaveEitherTypeOrNamepath = (tagName) => {
202-
return jsdocUtils.tagMustHaveEitherTypeOrNamepath(tagName);
201+
utils.tagMustHaveEitherTypeOrNamePosition = (tagName) => {
202+
return jsdocUtils.tagMustHaveEitherTypeOrNamePosition(tagName);
203203
};
204204

205-
utils.tagMightHaveEitherTypeOrNamepath = (tagName) => {
206-
return jsdocUtils.tagMightHaveEitherTypeOrNamepath(mode, tagName);
205+
utils.tagMightHaveEitherTypeOrNamePosition = (tagName) => {
206+
return jsdocUtils.tagMightHaveEitherTypeOrNamePosition(mode, tagName);
207207
};
208208

209-
utils.tagMustHaveNamepath = (tagName) => {
210-
return jsdocUtils.tagMustHaveNamepath(tagName);
209+
utils.tagMustHaveNamePosition = (tagName) => {
210+
return jsdocUtils.tagMustHaveNamePosition(tagName);
211211
};
212212

213-
utils.tagMightHaveNamepath = (tagName) => {
214-
return jsdocUtils.tagMightHaveNamepath(tagName);
213+
utils.tagMightHaveNamePosition = (tagName) => {
214+
return jsdocUtils.tagMightHaveNamePosition(tagName);
215215
};
216216

217-
utils.tagMustHaveType = (tagName) => {
218-
return jsdocUtils.tagMustHaveType(tagName);
217+
utils.tagMustHaveTypePosition = (tagName) => {
218+
return jsdocUtils.tagMustHaveTypePosition(tagName);
219219
};
220220

221-
utils.tagMightHaveAType = (tagName) => {
222-
return jsdocUtils.tagMightHaveAType(mode, tagName);
221+
utils.tagMightHaveTypePosition = (tagName) => {
222+
return jsdocUtils.tagMightHaveTypePosition(mode, tagName);
223223
};
224224

225225
utils.isNamepathDefiningTag = (tagName) => {

src/jsdocUtils.js

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,7 @@ const hasDefinedTypeReturnTag = (tag) => {
174174
return true;
175175
};
176176

177-
// Todo: These type and namepath tag listings currently look
178-
// at tags with `{...}` as being a type, but jsdoc may
179-
// allow some namepaths only within brackets as well
180-
181-
const tagsWithMandatoryType = [
177+
const tagsWithMandatoryTypePosition = [
182178
// These both show curly brackets in the doc signature and examples
183179
// "typeExpression"
184180
'implements',
@@ -192,7 +188,7 @@ const tagsWithMandatoryType = [
192188
// `param`/`arg`/`argument` (no signature)
193189
// `property`/`prop` (no signature)
194190
// `modifies` (undocumented)
195-
const tagsWithOptionalType = [
191+
const tagsWithOptionalTypePosition = [
196192
// These have the example showing curly brackets but not in their doc signature, e.g.: https://jsdoc.app/tags-enum.html
197193
'enum',
198194
'member', 'var',
@@ -225,8 +221,8 @@ const tagsWithOptionalType = [
225221
'modifies',
226222
];
227223

228-
const tagsWithOptionalTypeClosure = [
229-
...tagsWithOptionalType,
224+
const tagsWithOptionalTypePositionClosure = [
225+
...tagsWithOptionalTypePosition,
230226

231227
// Shows the signature with curly brackets but not in the example
232228
// "typeExpression"
@@ -257,7 +253,8 @@ const namepathDefiningTags = [
257253
'namespace',
258254

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

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

268265
// The following do not seem to allow curly brackets in their doc
269266
// signature or examples (besides `modifies`)
270-
const tagsWithOptionalNamepath = [
267+
const tagsWithOptionalNamePosition = [
271268
...namepathDefiningTags,
272269

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

300297
// The doc signature of `event` seems to require a "name"
301-
const tagsWithMandatoryNamepath = [
298+
const tagsWithMandatoryNamePosition = [
302299
// "name" (and a special syntax for the `external` name)
303300
'external', 'host',
304301

@@ -308,7 +305,7 @@ const tagsWithMandatoryNamepath = [
308305
'typedef',
309306
];
310307

311-
const tagsWithMandatoryTypeOrNamepath = [
308+
const tagsWithMandatoryTypeOrNamePosition = [
312309
// "namepath"
313310
'alias',
314311
'augments', 'extends',
@@ -330,30 +327,30 @@ const isNamepathDefiningTag = (tagName) => {
330327
return namepathDefiningTags.includes(tagName);
331328
};
332329

333-
const tagMightHaveAType = (mode, tag) => {
334-
return tagsWithMandatoryType.includes(tag) || (mode === 'closure' ?
335-
tagsWithOptionalTypeClosure.includes(tag) :
336-
tagsWithOptionalType.includes(tag));
330+
const tagMightHaveTypePosition = (mode, tag) => {
331+
return tagsWithMandatoryTypePosition.includes(tag) || (mode === 'closure' ?
332+
tagsWithOptionalTypePositionClosure.includes(tag) :
333+
tagsWithOptionalTypePosition.includes(tag));
337334
};
338335

339-
const tagMustHaveType = (tag) => {
340-
return tagsWithMandatoryType.includes(tag);
336+
const tagMustHaveTypePosition = (tag) => {
337+
return tagsWithMandatoryTypePosition.includes(tag);
341338
};
342339

343-
const tagMightHaveNamepath = (tag) => {
344-
return tagsWithOptionalNamepath.includes(tag);
340+
const tagMightHaveNamePosition = (tag) => {
341+
return tagsWithOptionalNamePosition.includes(tag);
345342
};
346343

347-
const tagMustHaveNamepath = (tag) => {
348-
return tagsWithMandatoryNamepath.includes(tag);
344+
const tagMustHaveNamePosition = (tag) => {
345+
return tagsWithMandatoryNamePosition.includes(tag);
349346
};
350347

351-
const tagMightHaveEitherTypeOrNamepath = (mode, tag) => {
352-
return tagMightHaveAType(mode, tag) || tagMightHaveNamepath(tag);
348+
const tagMightHaveEitherTypeOrNamePosition = (mode, tag) => {
349+
return tagMightHaveTypePosition(mode, tag) || tagMightHaveNamePosition(tag);
353350
};
354351

355-
const tagMustHaveEitherTypeOrNamepath = (tag) => {
356-
return tagsWithMandatoryTypeOrNamepath.includes(tag);
352+
const tagMustHaveEitherTypeOrNamePosition = (tag) => {
353+
return tagsWithMandatoryTypeOrNamePosition.includes(tag);
357354
};
358355

359356
/**
@@ -539,10 +536,10 @@ export default {
539536
isNamepathDefiningTag,
540537
isValidTag,
541538
parseClosureTemplateTag,
542-
tagMightHaveAType,
543-
tagMightHaveEitherTypeOrNamepath,
544-
tagMightHaveNamepath,
545-
tagMustHaveEitherTypeOrNamepath,
546-
tagMustHaveNamepath,
547-
tagMustHaveType,
539+
tagMightHaveEitherTypeOrNamePosition,
540+
tagMightHaveNamePosition,
541+
tagMightHaveTypePosition,
542+
tagMustHaveEitherTypeOrNamePosition,
543+
tagMustHaveNamePosition,
544+
tagMustHaveTypePosition,
548545
};

src/rules/checkTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default iterateJsdoc(({
5656
context,
5757
}) => {
5858
const jsdocTagsWithPossibleType = utils.filterTags((tag) => {
59-
return utils.tagMightHaveAType(tag.tag);
59+
return utils.tagMightHaveTypePosition(tag.tag);
6060
});
6161

6262
const {preferredTypes} = settings;

src/rules/noUndefinedTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default iterateJsdoc(({
106106
.concat(settings.mode === 'jsdoc' ? [] : closureGenericTypes);
107107

108108
const jsdocTagsWithPossibleType = utils.filterTags((tag) => {
109-
return utils.tagMightHaveAType(tag.tag);
109+
return utils.tagMightHaveTypePosition(tag.tag);
110110
});
111111

112112
jsdocTagsWithPossibleType.forEach((tag) => {

src/rules/validTypes.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ export default iterateJsdoc(({
7373
return true;
7474
};
7575

76-
const hasType = utils.tagMightHaveAType(tag.tag) && Boolean(tag.type);
77-
const mustHaveType = utils.tagMustHaveType(tag.tag);
76+
const hasTypePosition = utils.tagMightHaveTypePosition(tag.tag) && Boolean(tag.type);
77+
const mustHaveTypePosition = utils.tagMustHaveTypePosition(tag.tag);
7878

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

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

8585
if (tag.tag === 'borrows') {
8686
const thisNamepath = tag.description.replace(asExpression, '');
@@ -103,16 +103,16 @@ export default iterateJsdoc(({
103103
return;
104104
}
105105

106-
if (hasType) {
106+
if (hasTypePosition) {
107107
validTypeParsing(tag.type);
108-
} else if (mustHaveType) {
108+
} else if (mustHaveTypePosition) {
109109
report(`Tag @${tag.tag} must have a type`, null, tag);
110110
}
111111

112-
if (hasNamePath) {
112+
if (hasNameOrNamepathPosition) {
113113
validNamepathParsing(tag.name, tag.tag);
114-
} else if (mustHaveNamepath) {
115-
report(`Tag @${tag.tag} must have a namepath`, null, tag);
114+
} else if (mustHaveNameOrNamepathPosition) {
115+
report(`Tag @${tag.tag} must have a name/namepath`, null, tag);
116116
}
117117
}
118118
});

test/rules/assertions/validTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export default {
180180
`,
181181
errors: [{
182182
line: 3,
183-
message: 'Tag @callback must have a namepath',
183+
message: 'Tag @callback must have a name/namepath',
184184
}],
185185
options: [{
186186
allowEmptyNamepaths: false,

0 commit comments

Comments
 (0)