From 74739c849bbb6547b0e555ed8bb2ba1cbe0fdce4 Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Mon, 4 Dec 2023 15:48:03 -0500 Subject: [PATCH] fix: suggestion with invalid syntax in no-promise-executor-return rule (#17812) --- lib/rules/no-promise-executor-return.js | 15 +++++++++------ tests/lib/rules/no-promise-executor-return.js | 9 +++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/rules/no-promise-executor-return.js b/lib/rules/no-promise-executor-return.js index e6ed7a22efc..b27e440729c 100644 --- a/lib/rules/no-promise-executor-return.js +++ b/lib/rules/no-promise-executor-return.js @@ -209,12 +209,15 @@ module.exports = { }); } - suggest.push({ - messageId: "wrapBraces", - fix(fixer) { - return curlyWrapFixer(sourceCode, node, fixer); - } - }); + // Do not suggest wrapping an unnamed FunctionExpression in braces as that would be invalid syntax. + if (!(node.body.type === "FunctionExpression" && !node.body.id)) { + suggest.push({ + messageId: "wrapBraces", + fix(fixer) { + return curlyWrapFixer(sourceCode, node, fixer); + } + }); + } context.report({ node: node.body, diff --git a/tests/lib/rules/no-promise-executor-return.js b/tests/lib/rules/no-promise-executor-return.js index ee8a53929fb..74ad523a031 100644 --- a/tests/lib/rules/no-promise-executor-return.js +++ b/tests/lib/rules/no-promise-executor-return.js @@ -891,17 +891,14 @@ ruleTester.run("no-promise-executor-return", rule, { }] }, { + + // No suggestion since an unnamed FunctionExpression inside braces is invalid syntax. code: "() => new Promise(() => function () {});", errors: [{ messageId: "returnsValue", type: "FunctionExpression", column: 25, - suggestions: [ - { - messageId: "wrapBraces", - output: "() => new Promise(() => {function () {}});" - } - ] + suggestions: [] }] }, {