Skip to content

Commit

Permalink
fix: suggestion with invalid syntax in no-promise-executor-return rule (
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Dec 4, 2023
1 parent e0cb960 commit 74739c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
15 changes: 9 additions & 6 deletions lib/rules/no-promise-executor-return.js
Expand Up @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions tests/lib/rules/no-promise-executor-return.js
Expand Up @@ -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: []
}]
},
{
Expand Down

0 comments on commit 74739c8

Please sign in to comment.