-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
RFC: break method chains in assignments if they don't fit after operator #10297
Conversation
Break after Prettier pr-10297 --parser babel Input: const kochabCooieGameOnOboleUnweaveWayWay = reduce(someLongString.split("jest version =").pop().split(EOL)[0].trim()) Output: const kochabCooieGameOnOboleUnweaveWayWay = reduce(
someLongString.split("jest version =").pop().split(EOL)[0].trim()
); Of course we should still do break after Prettier pr-10222 --parser babel Input: const kochabCooieGameOnOboleUnweaveWayWay = someLoooooooooooooooooooooooongerString.split("jest version =").pop().split(EOL)[0].trim(); Output: const kochabCooieGameOnOboleUnweaveWayWay =
someLoooooooooooooooooooooooongerString
.split("jest version =")
.pop()
.split(EOL)[0]
.trim(); |
@brodybits I'm trying to avoid splitting the chain visually into two pieces: BTW, your example with |
I like the output in this PR and the alternative.. (I prefer more lines more though) |
@lipis Have also a look at the diff this PR would produce in real-world code: |
# Conflicts: # src/language-js/print/assignment.js
Not a fan of this style. I stay neutral on this. |
@fisker Do you prefer the current or alternative output? #10297 (comment) |
This comment has been minimized.
This comment has been minimized.
current one, main reason is we can't write return
someLoooooooooooooooooooooooongerString
.split("jest version =")
.pop()
.split(EOL)[0]
.trim(); |
|
I don't know, I'm just saying I won't write in this way myself. BTW, if I have to choose between alternative one and this one, I choose this one. |
The alternative output now (after #10222) happens when the LHS is so long that even the head of the chain doesn't fit on the first line. This PR naturally solves that too. But we can consider solving only that case instead. On the other hand, the alternative output looks definitely bad specifically for this chain only because the general method chain breaking heuristic should be improved. A mixed chain of this length with both |
Closing. The method chain breaking heuristic should be improved instead. |
Description
Proposal: if the right-hand side of an assignment is a member chain, then:
Input:
Current output (playground):
Output, this PR (playground):
Alternative output (should we prefer it probably?):
I like this idea, but 1) I somewhat dislike the implementation (this is just a PoC, I'll refactor/fix it if we decide to go this way), 2) would be good to hear opinions.
Checklist
docs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨