From 3089a921ac090dac32fd5289f7e5b519c3d57917 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sun, 6 Jun 2021 17:33:02 +0800 Subject: [PATCH] fix(`require-jsdoc`): `exemptEmptyFunctions` option could trigger problematic return value checking behavior with no-argument functions --- src/jsdocUtils.js | 7 ++++++ src/rules/requireJsdoc.js | 2 +- test/rules/assertions/requireJsdoc.js | 36 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/jsdocUtils.js b/src/jsdocUtils.js index 715b94b34..0acde7c70 100644 --- a/src/jsdocUtils.js +++ b/src/jsdocUtils.js @@ -507,10 +507,17 @@ const isNewPromiseExpression = (node) => { node.callee.name === 'Promise'; }; +/** + * @callback PromiseFilter + * @param {object} node + * @returns {boolean} + */ + /** * Checks if a node has a return statement. Void return does not count. * * @param {object} node + * @param {PromiseFilter} promFilter * @returns {boolean|Node} */ // eslint-disable-next-line complexity diff --git a/src/rules/requireJsdoc.js b/src/rules/requireJsdoc.js index bfb392815..bfe51d02c 100644 --- a/src/rules/requireJsdoc.js +++ b/src/rules/requireJsdoc.js @@ -221,7 +221,7 @@ export default { exemptEmptyConstructors && jsdocUtils.isConstructor(node) ) { const functionParameterNames = jsdocUtils.getFunctionParameterNames(node); - if (!functionParameterNames.length && !jsdocUtils.hasReturnValue(node, context)) { + if (!functionParameterNames.length && !jsdocUtils.hasReturnValue(node)) { return; } } diff --git a/test/rules/assertions/requireJsdoc.js b/test/rules/assertions/requireJsdoc.js index 8c46c2b6b..f582dc870 100644 --- a/test/rules/assertions/requireJsdoc.js +++ b/test/rules/assertions/requireJsdoc.js @@ -3144,6 +3144,42 @@ function quux (foo) { } `, }, + { + code: ` + function commandFinished () { + return new Promise((resolve) => { + client.on('ev', () => { + resolve(); + }); + }); + } + `, + errors: [ + { + line: 2, + message: 'Missing JSDoc comment.', + }, + ], + ignoreReadme: true, + options: [{ + exemptEmptyFunctions: true, + require: { + FunctionDeclaration: true, + }, + }], + output: ` + /** + * + */ + function commandFinished () { + return new Promise((resolve) => { + client.on('ev', () => { + resolve(); + }); + }); + } + `, + }, ], valid: [{ code: `