Skip to content

Commit 18ca406

Browse files
committed
- Optimization: For no-undefined-types, only check tags expected to have types (as with check-types) or, for valid-types, tags expected to have types or namepaths
- Docs: For `valid-types`, indicate this grouping of name(path) defining vs. pointing tags
1 parent c269413 commit 18ca406

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

.README/rules/valid-types.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
Requires all types to be valid JSDoc or Closure compiler types without syntax errors.
44

5-
Also impacts behaviors on namepath-pointing or event-pointing tags:
5+
Also impacts behaviors on namepath (or event)-defining and pointing tags:
66

7-
1. `@alias`, `@augments`, `@extends`, `@lends`, `@memberof`, `@memberof!`, `@mixes`, `@name`, `@this`
8-
1. `@callback`, `@event`, `@listens`, `@fires`, `@emits`
9-
1. `@borrows`
7+
1. Name(path)-defining tags: `@alias`, `@augments`, `@extends`, `@lends`, `@memberof`, `@memberof!`, `@mixes`, `@this`
8+
1. Name(path)-pointing tags: `@class`, `@constructor`, `@constant`, `@const`, `@external`, `@host`, `@function`, `@func`, `@method`, `@interface`, `@member`, `@var`, `@mixin`, `@name`, `@namespace`, `@type`, `@typedef`
9+
1. Name(path)-defining tags (which may have value without namepath): `@callback`, `@event`
10+
1. Name(path)-pointing tags (which may have value without namepath): `@listens`, `@fires`, `@emits`
11+
1. Name(path)-pointing tags (multiple names in one): `@borrows`
1012

1113
The following apply to the above sets:
1214

13-
- Expect tags in set 1 or 2 to have a valid namepath if present
14-
- Prevent set 2 from being empty by setting `allowEmptyNamepaths` to `false` as these tags might have some indicative value without a path (but set 1 will always fail if empty)
15-
- For the special case of set 3, i.e., `@borrows <that namepath> as <this namepath>`, check that both namepaths are present and valid and ensure there is an `as ` between them.
15+
- Expect tags in set 1-4 to have a valid namepath if present
16+
- Prevent sets 3-4 from being empty by setting `allowEmptyNamepaths` to `false` as these tags might have some indicative value without a path (but sets 1-2 will always fail if empty)
17+
- For the special case of set 5, i.e., `@borrows <that namepath> as <this namepath>`, check that both namepaths are present and valid and ensure there is an `as ` between them.
1618

1719
|||
1820
|---|---|

src/jsdocUtils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,13 @@ const hasReturnValue = (node, context) => {
424424
throw new Error('Unknown element ' + node.type);
425425
};
426426

427+
/** @param {string} tag */
428+
/*
429+
const isInlineTag = (tag) => {
430+
return /^(@link|@linkcode|@linkplain|@tutorial) /.test(tag);
431+
};
432+
*/
433+
427434
export default {
428435
getFunctionParameterNames,
429436
getJsdocParameterNames,

src/rules/noUndefinedTypes.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export default iterateJsdoc(({
5454
.concat(extraTypes)
5555
.concat(typedefDeclarations);
5656

57-
jsdoc.tags.forEach((tag) => {
57+
const jsdocTags = jsdoc.tags.filter((tag) => {
58+
return utils.isTagWithType(tag.tag);
59+
});
60+
61+
jsdocTags.forEach((tag) => {
5862
let parsedType;
5963

6064
try {

src/rules/validTypes.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import {parse} from 'jsdoctypeparser';
22
import iterateJsdoc from '../iterateJsdoc';
33

4-
/** @param {string} tag */
5-
const isInlineTag = (tag) => {
6-
return /^(@link|@linkcode|@linkplain|@tutorial) /.test(tag);
7-
};
8-
94
const asExpression = /as\s+/;
105

116
export default iterateJsdoc(({
@@ -47,7 +42,7 @@ export default iterateJsdoc(({
4742
return;
4843
}
4944
validTypeParsing(tag.name);
50-
} else if (tag.type && !isInlineTag(tag.type)) {
45+
} else if (tag.type && utils.isTagWithType(tag.tag)) {
5146
validTypeParsing(tag.type);
5247
}
5348
});

0 commit comments

Comments
 (0)