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
Multiline lists are formatted wrong #16381
Comments
Added this to the 1.2 milestone. |
What's the rule for lists? Which of these are acceptable/advisable? var a = [1, 2, 3]; Set owner to @munificent. |
a and b are acceptable, and I think it's up to the user to choose which one they want. c and d are always wrong. I would probably have the formatter:
|
What about? var pairs = [ As a user I'd be frustrated if this got flattened. On the other hand, what should happen if I add another pair? var pairs = [ And what about long lists? Is there an acceptable version that does not have one item per line? |
This comment was originally written by @Fox32 I have a list defining a coordiantes for a cube with normals a texture coordinates. I want to use the formatter but the formatter will never be able to output it in the way I want it. Maybe it is better if the formatter don't touch the contents of the list. Then the user needs to do it on his own. Here is the example for my list. I added additional whitespaces to make it easier to read (every number is lining up, even if it negativ) and to seperate the position from the normals and texture coordinates. [ |
Great example. Thanks for chiming in! This is exactly why I'm leery of the formatter being too aggressive with lists. A couple of off the cuff thoughts: a) The formatter could ignore lists of this format: l = [ assuming that if the author put contents on a separate newline they know what they're doing. b) we could condition authors to use a doc convention to ensure their structure is left intact: l = [ (This will look familiar to eclipse Java users.) I'm not in love with (b) but I'm curious what your gut reaction is... |
This comment was originally written by @Fox32 I don't like version b), I think the assumption that the user knows what he does, if he adds spaces, is a good way. I first liked the idea 3. from comment #3, but this wouldn't work with the minus sign formatting thing in my example. |
Me too. Hence rule 4 above.
I'd preserve that formatting too, unless it goes over 80 columns.
Sure, you can have long inline lists if you want, as long as the fit 80 columns. Once they go over, you need a newline after the "[" and before the "]". |
Cool. Am I right that this list: var primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 87]; would be reformatted to: (A) var primes = [ ? On would it rather be: (B) var primes = [ ? |
I'd guess (A) based on the principle that that makes the fewest changes to the original code. |
Removed this from the 1.2 milestone. |
Removed this from the 1.6 milestone. |
Removed Oldschool-Milestone-1.6 label. |
Added AssumedStale label. |
This issue has been moved to dart-lang/dart_style#307. |
Source:
main() {
[
"this is a very long string that forces the list to wrap",
"this is a very long string that forces the list to wrap"
];
}
Output:
main() {
["this is a very long string that forces the list to wrap",
"this is a very long string that forces the list to wrap"];
}
Expected: It should stay formatted like the source.
The text was updated successfully, but these errors were encountered: