Skip to content

Only check tags expected to have types for no-undefined-types and valid-types #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .README/rules/valid-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

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

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

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

The following apply to the above sets:

- Expect tags in set 1 or 2 to have a valid namepath if present
- 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)
- 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.
- Expect tags in set 1-4 to have a valid namepath if present
- 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)
- 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.

|||
|---|---|
Expand Down
7 changes: 7 additions & 0 deletions src/jsdocUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,13 @@ const hasReturnValue = (node, context) => {
throw new Error('Unknown element ' + node.type);
};

/** @param {string} tag */
/*
const isInlineTag = (tag) => {
return /^(@link|@linkcode|@linkplain|@tutorial) /.test(tag);
};
*/

export default {
getFunctionParameterNames,
getJsdocParameterNames,
Expand Down
6 changes: 5 additions & 1 deletion src/rules/noUndefinedTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export default iterateJsdoc(({
.concat(extraTypes)
.concat(typedefDeclarations);

jsdoc.tags.forEach((tag) => {
const jsdocTags = jsdoc.tags.filter((tag) => {
return utils.isTagWithType(tag.tag);
});

jsdocTags.forEach((tag) => {
let parsedType;

try {
Expand Down
7 changes: 1 addition & 6 deletions src/rules/validTypes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import {parse} from 'jsdoctypeparser';
import iterateJsdoc from '../iterateJsdoc';

/** @param {string} tag */
const isInlineTag = (tag) => {
return /^(@link|@linkcode|@linkplain|@tutorial) /.test(tag);
};

const asExpression = /as\s+/;

export default iterateJsdoc(({
Expand Down Expand Up @@ -47,7 +42,7 @@ export default iterateJsdoc(({
return;
}
validTypeParsing(tag.name);
} else if (tag.type && !isInlineTag(tag.type)) {
} else if (tag.type && utils.isTagWithType(tag.tag)) {
validTypeParsing(tag.type);
}
});
Expand Down