Skip to content

valid-types: Add more type checks #308

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
Show all changes
37 commits
Select commit Hold shift + click to select a range
f5c485d
feat(valid-types): Add more type checks
l1bbcsg Jul 4, 2019
4f71560
Fix reported line numbers
l1bbcsg Jul 5, 2019
4549593
docs: generate docs
l1bbcsg Jul 5, 2019
fec8b67
Merge branch 'master' into add-more-type-checks-to-valid-types
brettz9 Jul 6, 2019
efa0e68
Merge branch 'master' into add-more-type-checks-to-valid-types
brettz9 Jul 6, 2019
38a13e7
Merge branch 'master' into add-more-type-checks-to-valid-types
brettz9 Jul 7, 2019
04d5ba0
Merge branch 'master' into add-more-type-checks-to-valid-types
brettz9 Jul 7, 2019
47472d0
Merge commit 'f44b25ed4cb521116a682a0d8d10406f3440cec7' into add-more…
brettz9 Jul 7, 2019
89cd7f9
Merge branch 'master' into add-more-type-checks-to-valid-types
brettz9 Jul 7, 2019
9fa7b52
Merge branch 'master' into add-more-type-checks-to-valid-types
brettz9 Jul 8, 2019
78a0cba
Merge branch 'master' into add-more-type-checks-to-valid-types
brettz9 Jul 14, 2019
602d210
Merge branch 'master' into add-more-type-checks-to-valid-types
brettz9 Jul 14, 2019
765f6ed
Merge branch 'master' into add-more-type-checks-to-valid-types
brettz9 Jul 18, 2019
b4beb95
Merge branch 'master' into add-more-type-checks-to-valid-types
brettz9 Jul 21, 2019
ea3e057
fix(require-example): add fixer for missing declaration (though can d…
brettz9 Jul 22, 2019
c8d0611
fix(require-param): skip destructuring; fixes #352 (though still need…
brettz9 Jul 22, 2019
19a6590
feat: allow empty line between jsdoc and jscode (#353)
yeonjuan Jul 23, 2019
37e8300
fix(require-returns-check): check `WithStatement` for `return` statem…
brettz9 Jul 23, 2019
b48cf1d
fix(require-jsdoc): add fixer to add empty jsdoc block
brettz9 Jul 24, 2019
e456c50
docs(`require-returns-check`): update docs
golopot Jul 24, 2019
c3b56c6
refactor(`require-returns`): simplify util.hasReturnValue
golopot Jul 25, 2019
23846fc
feat(`check-types`): Add `symbol` and `bigint` to native types (fixes…
brettz9 Jul 29, 2019
982debb
chore: update devDeps and apply `comma-dangle` linting rule
brettz9 Aug 7, 2019
2bfe7d8
Cleanup after merging
l1bbcsg Aug 8, 2019
44f98a4
docs(valid-types) Update readme
l1bbcsg Aug 8, 2019
403c9db
Merge branch 'master' into feature/add-more-type-checks-to-valid-types
l1bbcsg Aug 8, 2019
5e0f9a5
Completely ignore @see {@link ...} tag in parser
l1bbcsg Aug 8, 2019
b897250
Refactor utils naming
l1bbcsg Aug 8, 2019
668ea89
Add couple more tests and reuse some utilites to fix coverage
l1bbcsg Aug 8, 2019
bccfebe
Call namepaths namepath instead of types in error messages
l1bbcsg Aug 8, 2019
cb02b85
Merge branch 'master' into add-more-type-checks-to-valid-types
brettz9 Aug 10, 2019
4aca635
Merge branch 'master' into add-more-type-checks-to-valid-types
brettz9 Sep 1, 2019
6b7ab34
refactor: remove mandatory type items from optional type items list a…
brettz9 Sep 1, 2019
24e8a57
docs: add todo comment to ensure handling gcc when mode added
brettz9 Sep 1, 2019
439fd99
refactor: rename variable without redundant "either"
brettz9 Sep 1, 2019
6081ff2
testing: remove namepath in test checking for empty namepath
brettz9 Sep 1, 2019
902fac0
testing: ensure we don't report `see` with `link` even with `checkSee…
brettz9 Sep 1, 2019
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
84 changes: 75 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7362,39 +7362,39 @@ function quux() {
function quux() {

}
// Message: Syntax error in type: module:namespace.SomeClass<~
// Message: Syntax error in namepath: module:namespace.SomeClass<~

/**
* @memberof module:namespace.SomeClass~<
*/
function quux() {

}
// Message: Syntax error in type: module:namespace.SomeClass~<
// Message: Syntax error in namepath: module:namespace.SomeClass~<

/**
* @borrows foo% as bar
*/
function quux() {

}
// Message: Syntax error in type: foo%
// Message: Syntax error in namepath: foo%

/**
* @borrows #foo as bar
*/
function quux() {

}
// Message: Syntax error in type: #foo
// Message: Syntax error in namepath: #foo

/**
* @borrows foo as bar%
*/
function quux() {

}
// Message: Syntax error in type: bar%
// Message: Syntax error in namepath: bar%

/**
* @borrows foo
Expand All @@ -7411,7 +7411,7 @@ function quux() {

}
// Options: [{"checkSeesForNamepaths":true}]
// Message: Syntax error in type: foo%
// Message: Syntax error in namepath: foo%

/** */
function foo() {}
Expand All @@ -7424,15 +7424,15 @@ function foo() {}
function quux() {

}
// Message: Syntax error in type: module:abc#event:foo-bar
// Message: Syntax error in namepath: module:abc#event:foo-bar

/**
* @mixes module:namespace.SomeClass~
*/
function quux() {

}
// Message: Syntax error in type: module:namespace.SomeClass~
// Message: Syntax error in namepath: module:namespace.SomeClass~

/**
* @callback
Expand All @@ -7441,7 +7441,35 @@ function quux() {

}
// Options: [{"allowEmptyNamepaths":false}]
// Message: Syntax error in type:
// Message: Tag @callback must have a namepath

/**
* @constant {str%ng}
*/
const FOO = 'foo';
// Message: Syntax error in type: str%ng

/**
* @typedef {str%ng} UserString
*/
// Message: Syntax error in type: str%ng

/**
* @typedef {string} UserStr%ng
*/
// Message: Syntax error in namepath: UserStr%ng

/**
* @extends
*/
class Bar {};
// Message: Tag @extends must have either a type or namepath

/**
* @type
*/
let foo;
// Message: Tag @type must have a type
````

The following patterns are not considered problems:
Expand Down Expand Up @@ -7496,12 +7524,20 @@ function quux() {

}

/**
* @callback foo
*/
function quux() {

}

/**
* @callback
*/
function quux() {

}
// Options: [{"allowEmptyNamepaths":true}]

/**
* @class
Expand All @@ -7516,6 +7552,7 @@ function quux() {
function quux() {

}
// Options: [{"checkSeesForNamepaths":true}]

/**
*
Expand Down Expand Up @@ -7545,6 +7582,35 @@ function quux() {
function quux() {

}

/**
* @constant {string}
*/
const FOO = 'foo';

/**
* @constant {string} FOO
*/
const FOO = 'foo';

/**
* @extends Foo
*/
class Bar {};

/**
* @extends {Foo<String>}
*/
class Bar {};

/**
* @typedef {number|string} UserDefinedType
*/

/**
* @typedef {number|string}
*/
let UserDefinedGCCType;
````


56 changes: 40 additions & 16 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,31 @@ import getJSDocComment from './eslint/getJSDocComment';
* @returns {object}
*/
const parseComment = (commentNode, indent, trim = true) => {
const skipSeeLink = (parser) => {
return (str, data) => {
if (data.tag === 'see' && str.match(/{@link.+?}/)) {
return null;
}

return parser(str, data);
};
};

// Preserve JSDoc block start/end indentation.
return commentParser(`${indent}/*${commentNode.value}${indent}*/`, {
// @see https://github.com/yavorskiy/comment-parser/issues/21
parsers: [
commentParser.PARSERS.parse_tag,
commentParser.PARSERS.parse_type,
(str, data) => {
if (['example', 'return', 'returns', 'throws', 'exception'].includes(data.tag)) {
return null;
}
skipSeeLink(commentParser.PARSERS.parse_type),
skipSeeLink(
(str, data) => {
if (['example', 'return', 'returns', 'throws', 'exception'].includes(data.tag)) {
return null;
}

return commentParser.PARSERS.parse_name(str, data);
},
return commentParser.PARSERS.parse_name(str, data);
},
),
trim ?
commentParser.PARSERS.parse_description :

Expand Down Expand Up @@ -181,20 +193,32 @@ const getUtils = (
return false;
};

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

utils.tagMightHaveEitherTypeOrNamepath = (tagName) => {
return jsdocUtils.tagMightHaveEitherTypeOrNamepath(tagName);
};
utils.isNamepathTag = (tagName, checkSeesForNamepaths) => {
return jsdocUtils.isNamepathTag(tagName, checkSeesForNamepaths);

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

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

utils.passesEmptyNamepathCheck = (tag, allowEmptyNamepaths) => {
return !tag.name && allowEmptyNamepaths &&
jsdocUtils.isPotentiallyEmptyNamepathTag(tag.tag);
utils.tagMustHaveType = (tagName) => {
return jsdocUtils.tagMustHaveType(tagName);
};

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

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

utils.hasDefinedTypeReturnTag = (tag) => {
Expand Down
Loading