Skip to content

Commit

Permalink
fix(require-jsdoc): exemptEmptyFunctions option could trigger pro…
Browse files Browse the repository at this point in the history
…blematic return value checking behavior with no-argument functions
  • Loading branch information
brettz9 committed Jun 6, 2021
1 parent 318e104 commit 3089a92
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/jsdocUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rules/requireJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
36 changes: 36 additions & 0 deletions test/rules/assertions/requireJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand Down

0 comments on commit 3089a92

Please sign in to comment.