-
Notifications
You must be signed in to change notification settings - Fork 125
Compound expressions in return statements format poorly (WONTFIX) #525
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
Comments
Here's another example: return a.storage[0] == 1.0 // col 1
&& a.storage[1] == 0.0
&& a.storage[2] == 0.0
&& a.storage[3] == 0.0
&& a.storage[4] == 0.0 // col 2
&& a.storage[5] == 1.0
&& a.storage[6] == 0.0
&& a.storage[7] == 0.0
&& a.storage[8] == 0.0 // col 3
&& a.storage[9] == 0.0
&& a.storage[10] == 1.0
&& a.storage[11] == 0.0
&& a.storage[12] == 0.0 // col 4
&& a.storage[13] == 0.0
&& a.storage[14] == 0.0
&& a.storage[15] == 1.0; Output: return a.storage[0] == 1.0 // col 1
&&
a.storage[1] == 0.0 &&
a.storage[2] == 0.0 &&
a.storage[3] == 0.0 &&
a.storage[4] == 0.0 // col 2
&&
a.storage[5] == 1.0 &&
a.storage[6] == 0.0 &&
a.storage[7] == 0.0 &&
a.storage[8] == 0.0 // col 3
&&
a.storage[9] == 0.0 &&
a.storage[10] == 1.0 &&
a.storage[11] == 0.0 &&
a.storage[12] == 0.0 // col 4
&&
a.storage[13] == 0.0 &&
a.storage[14] == 0.0 &&
a.storage[15] == 1.0; |
Another example, this from the Flutter rendering library: Input: return (minWidth <= size.width) && (size.width <= maxWidth) &&
(minHeight <= size.height) && (size.height <= maxHeight); Output: return (minWidth <= size.width) &&
(size.width <= maxWidth) &&
(minHeight <= size.height) &&
(size.height <= maxHeight); The original code here is carefully written so that it forms a two-by-two matrix with the vertical columns being minimum and maximum, and the horizontal rows being width and height, with each column having the form "a < b < c". However, the formatter removes all of this and the code ends up much harder to understand at a glance. |
To clarify: I care a little about the first here, the second I think we could work around my moving the comments. The third is the most important IMHO. @sethladd suggests that for the third we could hint to the formatter that things should be kept on one line by putting parens around the first two and the last two expressions. That does seem to work, the output is then: return ((minWidth <= size.width) && (size.width <= maxWidth)) &&
((minHeight <= size.height) && (size.height <= maxHeight)); It would definitely be better if the second line of the return expression was aligned with the first though. |
I've filed the indent thing separately in #532. This means that this issue is really only about the first two examples, which basically boil down to noticing that you can put the |
It's not hard to implement, but it goes against the style guide and the millions of lines of existing Dart code that are already formatted with binary operators on the previous line. We did discuss changing this a while back, and the consensus on the team at the time was that keeping the operators on the right was better. |
This flutter code:
...becomes less readable when processed by dartfmt:
It's not as readable as the original but I would also have accepted:
The text was updated successfully, but these errors were encountered: