Skip to content

Commit

Permalink
Chore: improve arrow-body-style error message (refs #5498) (#9718)
Browse files Browse the repository at this point in the history
#5498 gets more than twice as
much traffic as any of our other issues. My interpretation of this fact
is that people are often confused by errors from the `arrow-body-style`
rule, and end up searching and finding that issue. This commit updates
the error message for `arrow-body-style` to be more specific about how
to fix the problem.
  • Loading branch information
not-an-aardvark committed Dec 16, 2017
1 parent f819920 commit 14baa2e
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 27 deletions.
14 changes: 13 additions & 1 deletion lib/rules/arrow-body-style.js
Expand Up @@ -109,10 +109,22 @@ module.exports = {
}

if (never || asNeeded && blockBody[0].type === "ReturnStatement") {
let message;

if (blockBody.length === 0) {
message = "Unexpected block statement surrounding arrow body; put a value of `undefined` immediately after the `=>`.";
} else if (blockBody.length > 1) {
message = "Unexpected block statement surrounding arrow body.";
} else if (astUtils.isOpeningBraceToken(sourceCode.getFirstToken(blockBody[0], { skip: 1 }))) {
message = "Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`.";
} else {
message = "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`.";
}

context.report({
node,
loc: arrowBody.loc.start,
message: "Unexpected block statement surrounding arrow body.",
message,
fix(fixer) {
const fixes = [];

Expand Down

0 comments on commit 14baa2e

Please sign in to comment.