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
Chore: improve arrow-body-style error message (refs #5498) #9718
Conversation
#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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left one comment about a message I'm not sure about, but otherwise this is a great change in the right direction. Thanks for your consideration.
lib/rules/arrow-body-style.js
Outdated
let message; | ||
|
||
if (blockBody.length === 0) { | ||
message = "Unexpected block statement surrounding arrow body; put `undefined` immediately after the `=>`."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I like this message because undefined
isn't a keyword and some folks might prefer void 0
or some other equivalent. Is there a way we can improve it? (I haven't got anything concrete now, sorry.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would something like "move a value of undefined
right after the =>
" be better?
Alternatively, we could just use the old message for this case rather than adding an additional clause.
Personally, I think that:
- The error message is only supposed to describe how to fix the
arrow-body-style
problem; as usual, a fix could conflict with another rule. - This is just a message for users and not an autofix, so we can assume users are willing to make some changes to the fix so that it fits within their code style.
- In a project that doesn't use the
undefined
identifier, I assume users would be familiar with the alternatives for using theundefined
identifier, so they would be able to create an appropriate replacement for the expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your alternative message suggestion. Ultimately this isn't a hill I want to die on, so just let me know what you decide and if you need me to review again. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to change the message to:
Unexpected block statement surrounding arrow body; put a value of
undefined
immediately after the=>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
What is the purpose of this pull request? (put an "X" next to item)
[x] Other, please explain:
What changes did you make? (Give an overview)
#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 forarrow-body-style
to be more specific about how to fix the problem.Is there anything you'd like reviewers to focus on?
Any wording suggestions?