diff --git a/lib/rules/no-promise-executor-return.js b/lib/rules/no-promise-executor-return.js index 59eded0a0f3..e6ed7a22efc 100644 --- a/lib/rules/no-promise-executor-return.js +++ b/lib/rules/no-promise-executor-return.js @@ -74,7 +74,7 @@ function expressionIsVoid(node) { * @param {Object} sourceCode context given by context.sourceCode * @param {ASTNode} node The node to fix. * @param {Object} fixer The fixer object provided by ESLint. - * @returns {Array|Object} - An array of fix objects or fix to apply to the node. + * @returns {Array} - An array of fix objects to apply to the node. */ function voidPrependFixer(sourceCode, node, fixer) { @@ -100,10 +100,10 @@ function voidPrependFixer(sourceCode, node, fixer) { const prependSpace = - // is return token, as => allows ( to be adjacent + // is return token, as => allows void to be adjacent returnOrArrowToken.value === "return" && - // If two tokens (return and ")") are adjacent + // If two tokens (return and "(") are adjacent returnOrArrowToken.range[1] === firstToken.range[0]; return [ @@ -117,11 +117,11 @@ function voidPrependFixer(sourceCode, node, fixer) { * @param {Object} sourceCode context given by context.sourceCode * @param {ASTNode} node The node to fix. * @param {Object} fixer The fixer object provided by ESLint. - * @returns {Array} - An array of fix objects or fix to apply to the node. + * @returns {Array} - An array of fix objects to apply to the node. */ function curlyWrapFixer(sourceCode, node, fixer) { - // @mdjermanovic https://github.com/eslint/eslint/pull/17282#issuecomment-1592795923 + // https://github.com/eslint/eslint/pull/17282#issuecomment-1592795923 const arrowToken = sourceCode.getTokenBefore(node.body, astUtils.isArrowToken); const firstToken = sourceCode.getTokenAfter(arrowToken); const lastToken = sourceCode.getLastToken(node); diff --git a/tests/lib/rules/no-promise-executor-return.js b/tests/lib/rules/no-promise-executor-return.js index 8651f61f0eb..4054edc7244 100644 --- a/tests/lib/rules/no-promise-executor-return.js +++ b/tests/lib/rules/no-promise-executor-return.js @@ -172,8 +172,8 @@ ruleTester.run("no-promise-executor-return", rule, { }, /* - * void - * arrow functions + void return is allowed + * allowVoid: true + * `=> void` and `return void` are allowed */ { code: "new Promise((r) => void cbf(r));", @@ -475,7 +475,7 @@ ruleTester.run("no-promise-executor-return", rule, { errors: [eReturnsValue()] }, - // void return is not allowed unless arrow function expression + // `return void` is not allowed without `allowVoid: true` { code: "new Promise(() => { return void 1; })", errors: [eReturnsValue()]