From f7c8038ec6e2af25577b524be0cd33fa7a6101ba Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 19 Jun 2021 13:58:31 +0800 Subject: [PATCH] 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.) --- README.md | 6 ++++++ src/jsdocUtils.js | 2 +- test/rules/assertions/requireThrows.js | 12 ++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c1bda6c71..9e228f980 100644 --- a/README.md +++ b/README.md @@ -18051,6 +18051,12 @@ const itself = (n) => n; * Not tracking on nested function */ const nested = () => () => {throw new Error('oops');}; + +/** + */ +async function foo() { + throw Error("bar"); +} ```` diff --git a/src/jsdocUtils.js b/src/jsdocUtils.js index 8ddb714d1..c9b3c6ef7 100644 --- a/src/jsdocUtils.js +++ b/src/jsdocUtils.js @@ -997,7 +997,7 @@ const hasThrowValue = (node, innerFunction) => { case 'FunctionExpression': case 'FunctionDeclaration': case 'ArrowFunctionExpression': { - return !innerFunction && hasThrowValue(node.body, true); + return !innerFunction && !node.async && hasThrowValue(node.body, true); } case 'BlockStatement': { return node.body.some((bodyNode) => { diff --git a/test/rules/assertions/requireThrows.js b/test/rules/assertions/requireThrows.js index 8b1b9eaef..d4f0e062e 100644 --- a/test/rules/assertions/requireThrows.js +++ b/test/rules/assertions/requireThrows.js @@ -418,5 +418,17 @@ export default { const nested = () => () => {throw new Error('oops');}; `, }, + { + code: ` + /** + */ + async function foo() { + throw Error("bar"); + } + `, + parserOptions: { + ecmaVersion: 8, + }, + }, ], };