Skip to content

Commit 897f205

Browse files
authored
fix: correct error message of check-types (fixes #103)
Fix: correct error message of `check-types` (fixes #103)
2 parents 2619665 + 6c172eb commit 897f205

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,15 @@ function quux (foo) {
983983
}
984984
// Message: Invalid JSDoc @arg "foo" type "Number".
985985

986+
/**
987+
* @returns {Number} foo
988+
* @throws {Number} foo
989+
*/
990+
function quux () {
991+
992+
}
993+
// Message: Invalid JSDoc @returns type "Number".
994+
986995
/**
987996
* @param {(Number|string|Boolean)=} foo
988997
*/

src/iterateJsdoc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const parseComment = (commentNode, indent) => {
1010
commentParser.PARSERS.parse_tag,
1111
commentParser.PARSERS.parse_type,
1212
(str, data) => {
13-
if (_.includes(['return', 'returns'], data.tag)) {
13+
if (_.includes(['return', 'returns', 'throws', 'exception'], data.tag)) {
1414
return null;
1515
}
1616

src/rules/checkTypes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ export default iterateJsdoc(({
8080
return fixer.replaceText(jsdocNode, sourceCode.getText(jsdocNode).replace('{' + jsdocTag.type + '}', '{' + fixedType + '}'));
8181
};
8282

83-
report('Invalid JSDoc @' + jsdocTag.tag + ' "' + jsdocTag.name + '" type "' + invalidType + '".', fix, jsdocTag);
83+
const name = jsdocTag.name ? ' "' + jsdocTag.name + '"' : '';
84+
85+
report('Invalid JSDoc @' + jsdocTag.tag + name + ' type "' + invalidType + '".', fix, jsdocTag);
8486
});
8587
}
8688
});

test/rules/assertions/checkTypes.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ export default {
4848
}
4949
`
5050
},
51+
{
52+
code: `
53+
/**
54+
* @returns {Number} foo
55+
* @throws {Number} foo
56+
*/
57+
function quux () {
58+
59+
}
60+
`,
61+
errors: [
62+
{
63+
line: 3,
64+
message: 'Invalid JSDoc @returns type "Number".'
65+
},
66+
{
67+
line: 4,
68+
message: 'Invalid JSDoc @throws type "Number".'
69+
}
70+
]
71+
},
5172
{
5273
code: `
5374
/**

0 commit comments

Comments
 (0)