Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: suggestion with invalid syntax in no-promise-executor-return rule #17812

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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