Skip to content

Commit

Permalink
add test case and fix error message
Browse files Browse the repository at this point in the history
Fixes #35
  • Loading branch information
Alexej Yaroshevich committed Nov 11, 2014
1 parent 955d3ac commit 1ed53d8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@ function DocType(type, loc) {
var data = parsed.valid ? _simplifyType(parsed) : [];

this.optional = parsed.optional;
this.variable = parsed.variable;
this.valid = parsed.valid;

if (parsed.valid && parsed.variable) {
this.loc.column = this.loc.column + 3;
}

/**
* match type
* @param {EsprimaNode} node
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/validate-jsdoc/check-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function validateTypesInTags(file, errors) {
}
if (!tag.type.valid) {
// throw an error if not valid
errors.add('jsDoc checkTypes: Expected valid type instead of ' + tag.type.value, tag.type.loc);
errors.add('expects valid type instead of ' + tag.type.value, tag.type.loc);
}
});
});
Expand Down
5 changes: 5 additions & 0 deletions test/lib/jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,20 @@ describe('jsdoc', function() {

describe('type', function() {
var bool1;
var varnum;

before(function() {
bool1 = new Type('boolean', new Location(3, 4));
varnum = new Type('...number', new Location(10, 20));
});

it('should store data', function() {
expect(bool1.value).to.eq('boolean');
expect(bool1.loc.line).to.eq(3);
expect(bool1.loc.column).to.eq(4);
expect(varnum.variable).to.eq(true);
expect(varnum.loc.line).to.eq(10);
expect(varnum.loc.column).to.eq(23);
});

it('should match types', function() {
Expand Down
15 changes: 15 additions & 0 deletions test/lib/rules/validate-jsdoc/check-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ describe('lib/rules/validate-jsdoc/check-types', function() {
ClsName.prototype.point = function (q, w) {
}
}
}, {
it: 'should not report invalid type for variable args (es6 rest). issue #35',
code: function() {
/**
* Returns the sum of all numbers passed to the function.
* @param {...number} num - A positive or negative number.
*/
function sum(num) {
var i = 0, n = arguments.length, t = 0;
for (; i < n; i++) {
t += arguments[i];
}
return t;
}
}
}
/* jshint ignore:end */
]);
Expand Down

0 comments on commit 1ed53d8

Please sign in to comment.