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
Update: Improve report location newline-per-chained-call (refs #12334) #13116
Conversation
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!
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.
Since we want to draw attention to the property, not just the dot, what do people think about specifying the location to start with the dot and end at the end of the property? (To me underlining only the dot looks strange, but happy to go along with consensus.)
I think @nzakas’s suggestion makes sense, particularly since that’s what the error message reports. 👍 |
Agreed, it would be great if we could think of something better than the dot. I found some possible problems with other solutions, which would also apply to underlining the dot and the property together. Error message /*eslint newline-per-chained-call: error*/
// lint-free
a.b().c().
foo(); So it might be more correct to start underlining from the property node, like it already works in the actual version? Also, this rule targets computed properties as well. These property nodes can be multiline, e.g.: /*eslint newline-per-chained-call: error*/
// Expected line break before `[f({`
a().b()[f({
prop: 1
})](); Should we, in this case, underline the whole property or maybe just the first token? Or perhaps only part of the property that is on the same line with the object, similar to how the error message works in the actual version ( |
I think including the dot is fine as I’d expect we would include the opening bracket for computed properties. While the dot case message might not be 100%, I think it’s close enough and it seems most people like the break before the dot. For long computed properties, I’d prefer to see the whole property underlined but only the first part in the actual error message. |
This should be done now. Some examples: |
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 for contributing! |
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[X] Other, please explain:
refs #12334
Change reported location in the
newline-per-chained-call
rule.This shouldn't produce any new warnings because it doesn't change the start line.
What changes did you make? (Give an overview)
Changed location to the full location of
.
or[
, instead of start location of theproperty
node.Before:
After:
Is there anything you'd like reviewers to focus on?
This looks like a big visual change. I chose this among many alternatives because it matches the place where the fixer inserts newline, and it's a common place to insert the newline manually (either on the left or on the right side). Also, the message starts with
.
/[