Skip to content

Commit 7d2d1e7

Browse files
committed
Merge pull request #47 from zxqfox/hotfix/vararg-param-error
add test case and fix error message
2 parents b182e71 + 1ed53d8 commit 7d2d1e7

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

lib/jsdoc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,13 @@ function DocType(type, loc) {
122122
var data = parsed.valid ? _simplifyType(parsed) : [];
123123

124124
this.optional = parsed.optional;
125+
this.variable = parsed.variable;
125126
this.valid = parsed.valid;
126127

128+
if (parsed.valid && parsed.variable) {
129+
this.loc.column = this.loc.column + 3;
130+
}
131+
127132
/**
128133
* match type
129134
* @param {EsprimaNode} node

lib/rules/validate-jsdoc/check-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function validateTypesInTags(file, errors) {
5757
}
5858
if (!tag.type.valid) {
5959
// throw an error if not valid
60-
errors.add('jsDoc checkTypes: Expected valid type instead of ' + tag.type.value, tag.type.loc);
60+
errors.add('expects valid type instead of ' + tag.type.value, tag.type.loc);
6161
}
6262
});
6363
});

test/lib/jsdoc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,20 @@ describe('jsdoc', function() {
3939

4040
describe('type', function() {
4141
var bool1;
42+
var varnum;
4243

4344
before(function() {
4445
bool1 = new Type('boolean', new Location(3, 4));
46+
varnum = new Type('...number', new Location(10, 20));
4547
});
4648

4749
it('should store data', function() {
4850
expect(bool1.value).to.eq('boolean');
4951
expect(bool1.loc.line).to.eq(3);
5052
expect(bool1.loc.column).to.eq(4);
53+
expect(varnum.variable).to.eq(true);
54+
expect(varnum.loc.line).to.eq(10);
55+
expect(varnum.loc.column).to.eq(23);
5156
});
5257

5358
it('should match types', function() {

test/lib/rules/validate-jsdoc/check-types.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ describe('lib/rules/validate-jsdoc/check-types', function() {
141141
ClsName.prototype.point = function (q, w) {
142142
}
143143
}
144+
}, {
145+
it: 'should not report invalid type for variable args (es6 rest). issue #35',
146+
code: function() {
147+
/**
148+
* Returns the sum of all numbers passed to the function.
149+
* @param {...number} num - A positive or negative number.
150+
*/
151+
function sum(num) {
152+
var i = 0, n = arguments.length, t = 0;
153+
for (; i < n; i++) {
154+
t += arguments[i];
155+
}
156+
return t;
157+
}
158+
}
144159
}
145160
/* jshint ignore:end */
146161
]);

0 commit comments

Comments
 (0)