Skip to content

Commit

Permalink
Fix: valid-jsdoc correctly checks type union (fixes #5260)
Browse files Browse the repository at this point in the history
Correctly checks type union when it is a property of type application
  • Loading branch information
kaicataldo committed Mar 14, 2016
1 parent 2c320da commit cfc14a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/valid-jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ module.exports = function(context) {
var elements = [];

if (tag.type.type === "TypeApplication") { // {Array.<String>}
elements = tag.type.applications;
elements = tag.type.applications[0].type === "UnionType" ? tag.type.applications[0].elements : tag.type.applications;
typesToCheck.push(getCurrentExpectedTypes(tag.type));
} else if (tag.type.type === "RecordType") { // {{20:String}}
elements = tag.type.fields;
Expand Down
28 changes: 28 additions & 0 deletions tests/lib/rules/valid-jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,34 @@ ruleTester.run("valid-jsdoc", rule, {
options: [{
"requireReturn": false
}]
},
{
code:
"/**\n" +
"* Foo\n" +
"* @param {Array.<string>} hi - desc\n" +
"* @returns {Array.<string|number>} desc\n" +
"*/\n" +
"function foo(hi){}",
options: [{
preferType: {
"String": "string"
}
}]
},
{
code:
"/**\n" +
"* Foo\n" +
"* @param {Array.<string|number>} hi - desc\n" +
"* @returns {Array.<string>} desc\n" +
"*/\n" +
"function foo(hi){}",
options: [{
preferType: {
"String": "string"
}
}]
}
],

Expand Down

0 comments on commit cfc14a9

Please sign in to comment.