Skip to content

Commit

Permalink
fixup bug in matching logic for custom classes
Browse files Browse the repository at this point in the history
Fixes #32
  • Loading branch information
Alexej Yaroshevich committed Nov 10, 2014
1 parent 3266c9e commit 8cfebde
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ function _simplifyType(node) {
return res;
}

var jsPrimitives = 'String Number Boolean Object Array Date Null Undefined Function Array RegExp'
.toLowerCase().split(' ');

/**
* Compare parsed jsDocTypes with esprima node
* @param {SimplifiedType[]} variants - result of jsDocParseType
Expand All @@ -278,6 +281,7 @@ function jsDocMatchType (variants, argument) {
var l;
var variant;
var type;
var primitive;
var result = null;

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

type = variant.type.toLowerCase();
primitive = jsPrimitives.indexOf(type) !== -1;

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

} else if (argument.type === 'ObjectExpression') {
result = result || (type === 'object' || type === 'class');
result = result || (type === 'object');
result = result || (!primitive);

} else if (argument.type === 'ArrayExpression') {
result = result || (type === 'array');
Expand Down
6 changes: 4 additions & 2 deletions test/lib/rules/validate-jsdoc/check-return-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,13 @@ describe('rules/validate-jsdoc', function () {
it: 'should not report on `@returns {Class}` for {}. issue #32',
code: function () {
/**
* @return {Class}
* @return {SomeObject}
*/
Users.prototype.getState = function()
{
return {};
return {
id: "main"
};
};
}
}
Expand Down

0 comments on commit 8cfebde

Please sign in to comment.