Skip to content

Commit

Permalink
fix: correct error message of check-types (fixes #103)
Browse files Browse the repository at this point in the history
Fix: correct error message of `check-types` (fixes #103)
  • Loading branch information
gajus authored Mar 14, 2019
2 parents 2619665 + 6c172eb commit 897f205
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,15 @@ function quux (foo) {
}
// Message: Invalid JSDoc @arg "foo" type "Number".

/**
* @returns {Number} foo
* @throws {Number} foo
*/
function quux () {

}
// Message: Invalid JSDoc @returns type "Number".

/**
* @param {(Number|string|Boolean)=} foo
*/
Expand Down
2 changes: 1 addition & 1 deletion src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const parseComment = (commentNode, indent) => {
commentParser.PARSERS.parse_tag,
commentParser.PARSERS.parse_type,
(str, data) => {
if (_.includes(['return', 'returns'], data.tag)) {
if (_.includes(['return', 'returns', 'throws', 'exception'], data.tag)) {
return null;
}

Expand Down
4 changes: 3 additions & 1 deletion src/rules/checkTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export default iterateJsdoc(({
return fixer.replaceText(jsdocNode, sourceCode.getText(jsdocNode).replace('{' + jsdocTag.type + '}', '{' + fixedType + '}'));
};

report('Invalid JSDoc @' + jsdocTag.tag + ' "' + jsdocTag.name + '" type "' + invalidType + '".', fix, jsdocTag);
const name = jsdocTag.name ? ' "' + jsdocTag.name + '"' : '';

report('Invalid JSDoc @' + jsdocTag.tag + name + ' type "' + invalidType + '".', fix, jsdocTag);
});
}
});
Expand Down
21 changes: 21 additions & 0 deletions test/rules/assertions/checkTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ export default {
}
`
},
{
code: `
/**
* @returns {Number} foo
* @throws {Number} foo
*/
function quux () {
}
`,
errors: [
{
line: 3,
message: 'Invalid JSDoc @returns type "Number".'
},
{
line: 4,
message: 'Invalid JSDoc @throws type "Number".'
}
]
},
{
code: `
/**
Expand Down

0 comments on commit 897f205

Please sign in to comment.