Skip to content
Permalink
Browse files

Fix: JSDoc for function expression on object property (fixes #4900)

  • Loading branch information...
tschaub committed Jan 12, 2016
1 parent 641ccd5 commit 0f469b4f7209ca65073b39d6885adc3784a6a436
Showing with 47 additions and 1 deletion.
  1. +1 −1 lib/util/source-code.js
  2. +46 −0 tests/lib/rules/valid-jsdoc.js
@@ -233,7 +233,7 @@ SourceCode.prototype = {
case "FunctionExpression":

if (parent.type !== "CallExpression" && parent.type !== "NewExpression") {
while (parent && !parent.leadingComments && !/Function/.test(parent.type) && parent.type !== "MethodDefinition") {
while (parent && !parent.leadingComments && !/Function/.test(parent.type) && parent.type !== "MethodDefinition" && parent.type !== "Property") {
parent = parent.parent;
}

@@ -39,6 +39,33 @@ ruleTester.run("valid-jsdoc", rule, {
"/**\n* Description\n* @override */\nfunction foo(arg1, arg2){ return ''; }",
"/**\n* Description\n* @inheritdoc */\nfunction foo(arg1, arg2){ return ''; }",
"/**\n* Description\n* @inheritDoc */\nfunction foo(arg1, arg2){ return ''; }",
{
code:
"/**\n" +
"* Create a new thing.\n" +
"*/\n" +
"var thing = new Thing({\n" +
" foo: function() {\n" +
" return 'bar';\n" +
" }\n" +
"});\n",
options: [{requireReturn: false}]
},
{
code:
"/**\n" +
"* Create a new thing.\n" +
"*/\n" +
"var thing = new Thing({\n" +
" /**\n" +
" * @return {string} A string.\n" +
" */\n" +
" foo: function() {\n" +
" return 'bar';\n" +
" }\n" +
"});\n",
options: [{requireReturn: false}]
},
{
code: "/**\n* Description\n* @return {void} */\nfunction foo(){}",
options: [{}]
@@ -234,6 +261,25 @@ ruleTester.run("valid-jsdoc", rule, {
type: "Block"
}]
},
{
code:
"/**\n" +
"* Create a new thing.\n" +
"*/\n" +
"var thing = new Thing({\n" +
" /**\n" +
" * Missing return tag.\n" +
" */\n" +
" foo: function() {\n" +
" return 'bar';\n" +
" }\n" +
"});\n",
options: [{requireReturn: false}],
errors: [{
message: "Missing JSDoc @returns for function.",
type: "Block"
}]
},
{
code: "/** @@returns {void} Foo */\nfunction foo(){}",
errors: [{

0 comments on commit 0f469b4

Please sign in to comment.
You can’t perform that action at this time.