Skip to content

Commit

Permalink
Fix: valid-jsdoc should allow optional returns for async (fixes #10386)…
Browse files Browse the repository at this point in the history
… (#10480)

Change valid-jsdoc to allow returns to be optional for async functions in the requireReturn:false case.
  • Loading branch information
Standard8 authored and not-an-aardvark committed Jun 25, 2018
1 parent 4c823bd commit 196c102
Show file tree
Hide file tree
Showing 2 changed files with 30 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 @@ -408,7 +408,7 @@ module.exports = {
if (!isOverride && !hasReturns && !hasConstructor && !isInterface &&
node.parent.kind !== "get" && node.parent.kind !== "constructor" &&
node.parent.kind !== "set" && !isTypeClass(node)) {
if (requireReturn || functionData.returnPresent) {
if (requireReturn || (functionData.returnPresent && !node.async)) {
context.report({
node: jsdocNode,
message: "Missing JSDoc @{{returns}} for function.",
Expand Down
29 changes: 29 additions & 0 deletions tests/lib/rules/valid-jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ ruleTester.run("valid-jsdoc", rule, {
ecmaVersion: 2017
}
},
{
code:
"/**\n" +
" * An async function. Options do not require return.\n" +
" */\n" +
"async function a() {}",
options: [{ requireReturn: false }],
parserOptions: {
ecmaVersion: 2017
}
},

// type validations
{
Expand Down Expand Up @@ -1677,6 +1688,24 @@ ruleTester.run("valid-jsdoc", rule, {
}]
},

// async function
{
code:
"/**\n" +
" * An async function. Options requires return.\n" +
" */\n" +
"async function a() {}",
output: null,
options: [{ requireReturn: true }],
parserOptions: {
ecmaVersion: 2017
},
errors: [{
message: "Missing JSDoc @returns for function.",
type: "Block"
}]
},

// type validations
{
code:
Expand Down

0 comments on commit 196c102

Please sign in to comment.