Skip to content

Commit f7c8038

Browse files
committed
fix: stop reporting for async functions with throw missing @throws; fixes #722
(To ensure the rejected value is documented, we may need a custom tag rule.)
1 parent 478b248 commit f7c8038

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18051,6 +18051,12 @@ const itself = (n) => n;
1805118051
* Not tracking on nested function
1805218052
*/
1805318053
const nested = () => () => {throw new Error('oops');};
18054+
18055+
/**
18056+
*/
18057+
async function foo() {
18058+
throw Error("bar");
18059+
}
1805418060
````
1805518061
1805618062

src/jsdocUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ const hasThrowValue = (node, innerFunction) => {
997997
case 'FunctionExpression':
998998
case 'FunctionDeclaration':
999999
case 'ArrowFunctionExpression': {
1000-
return !innerFunction && hasThrowValue(node.body, true);
1000+
return !innerFunction && !node.async && hasThrowValue(node.body, true);
10011001
}
10021002
case 'BlockStatement': {
10031003
return node.body.some((bodyNode) => {

test/rules/assertions/requireThrows.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,5 +418,17 @@ export default {
418418
const nested = () => () => {throw new Error('oops');};
419419
`,
420420
},
421+
{
422+
code: `
423+
/**
424+
*/
425+
async function foo() {
426+
throw Error("bar");
427+
}
428+
`,
429+
parserOptions: {
430+
ecmaVersion: 8,
431+
},
432+
},
421433
],
422434
};

0 commit comments

Comments
 (0)