Skip to content

Commit 2c83574

Browse files
committed
Merge pull request #43 from zxqfox/hotfix/invalid-match-logic-on-classes
fixup bug in matching logic for custom classes
2 parents 3266c9e + 8cfebde commit 2c83574

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/jsdoc.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ function _simplifyType(node) {
268268
return res;
269269
}
270270

271+
var jsPrimitives = 'String Number Boolean Object Array Date Null Undefined Function Array RegExp'
272+
.toLowerCase().split(' ');
273+
271274
/**
272275
* Compare parsed jsDocTypes with esprima node
273276
* @param {SimplifiedType[]} variants - result of jsDocParseType
@@ -278,6 +281,7 @@ function jsDocMatchType (variants, argument) {
278281
var l;
279282
var variant;
280283
var type;
284+
var primitive;
281285
var result = null;
282286

283287
for (i = 0, l = variants.length; i < l; i += 1) {
@@ -288,6 +292,7 @@ function jsDocMatchType (variants, argument) {
288292
}
289293

290294
type = variant.type.toLowerCase();
295+
primitive = jsPrimitives.indexOf(type) !== -1;
291296

292297
if (argument.type === 'Literal') {
293298
if (argument.value === null) {
@@ -307,7 +312,8 @@ function jsDocMatchType (variants, argument) {
307312
}
308313

309314
} else if (argument.type === 'ObjectExpression') {
310-
result = result || (type === 'object' || type === 'class');
315+
result = result || (type === 'object');
316+
result = result || (!primitive);
311317

312318
} else if (argument.type === 'ArrayExpression') {
313319
result = result || (type === 'array');

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,13 @@ describe('rules/validate-jsdoc', function () {
267267
it: 'should not report on `@returns {Class}` for {}. issue #32',
268268
code: function () {
269269
/**
270-
* @return {Class}
270+
* @return {SomeObject}
271271
*/
272272
Users.prototype.getState = function()
273273
{
274-
return {};
274+
return {
275+
id: "main"
276+
};
275277
};
276278
}
277279
}

0 commit comments

Comments
 (0)