Skip to content

Commit

Permalink
fix(require-returns): regression with forcing all async returns to …
Browse files Browse the repository at this point in the history
…be ignored; fixes #1019
  • Loading branch information
brettz9 committed Apr 17, 2023
1 parent b23a587 commit 41d1cf3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20446,6 +20446,22 @@ export function readFixture(path: string): void;
export function readFixture(path: string);
// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
// Message: Missing JSDoc @returns declaration.

/**
* @param {array} a
*/
async function foo(a) {
return Promise.all(a);
}
// Message: Missing JSDoc @returns declaration.

/**
* Description.
*/
export default async function demo() {
return true;
}
// Message: Missing JSDoc @returns declaration.
````

The following patterns are not considered problems:
Expand Down Expand Up @@ -20930,13 +20946,6 @@ async function foo() {
return new Promise(resolve => resolve());
}

/**
* @param {array} a
*/
async function foo(a) {
return Promise.all(a);
}

/**
* @param ms time in millis
*/
Expand Down
2 changes: 1 addition & 1 deletion src/rules/requireReturns.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default iterateJsdoc(({
return true;
}

return !isAsync && iteratingFunction && utils.hasValueOrExecutorHasNonEmptyResolveValue(
return iteratingFunction && utils.hasValueOrExecutorHasNonEmptyResolveValue(
forceReturnsWithAsync,
);
};
Expand Down
52 changes: 39 additions & 13 deletions test/rules/assertions/requireReturns.js
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,45 @@ export default {
],
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
/**
* @param {array} a
*/
async function foo(a) {
return Promise.all(a);
}
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @returns declaration.',
},
],
parserOptions: {
ecmaVersion: 8,
},
},
{
code: `
/**
* Description.
*/
export default async function demo() {
return true;
}
`,
errors: [
{
line: 2,
message: 'Missing JSDoc @returns declaration.',
},
],
parserOptions: {
ecmaVersion: 8,
sourceType: 'module',
},
},
],
valid: [
{
Expand Down Expand Up @@ -2562,19 +2601,6 @@ export default {
],
parser: require.resolve('@typescript-eslint/parser'),
},
{
code: `
/**
* @param {array} a
*/
async function foo(a) {
return Promise.all(a);
}
`,
parserOptions: {
ecmaVersion: 8,
},
},
{
code: `
/**
Expand Down

0 comments on commit 41d1cf3

Please sign in to comment.