-
Notifications
You must be signed in to change notification settings - Fork 120
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
wrong indent for lambda inside a method chain #755
Comments
This is similar to the conversation in #731, especially @munificent's last example. (Not that it's a duplicate, necessarily; just linking similar issues.) |
#731 is similar but I don't request the chain to be indented even further down the chain. As @munificent pointed out it would march farther and farther to the right. // requested solution in #731 (behaves poorly on long chains)
void testFormatting(List<String> list) {
list.reversed
.map((it) {
if (it.contains("a")) {
return it.toUpperCase();
} else {
return it.toLowerCase();
}
})
.map((it) => it.toString())
.map((it) => it.toString())
.map((it) => it.toString())
.map((it) => it.toString());
} I only request the multi-line lamda to be indented based on the receiving function rather than the outer function. |
The output here is deliberate, but not great. Formatting function literals inside method chains well is really hard. For any given set of rules I've come up with, there seem to be real examples in the wild that look bad. The current set of rules — which are quite complex — are a compromise between a lot of different needs. I'd like to do something better, but so far I haven't been able to come up with anything. |
The forthcoming tall style does what you want and gives the same formatting as the original input code: void testFormatting(List<String> list) {
list.reversed
.map((it) {
if (it.contains("a")) {
return it.toUpperCase();
} else {
return it.toLowerCase();
}
})
.expand((it) => it.runes)
.firstWhere((it) => it < "T".runes.first);
} |
dartfmt
makes method chains hard to read when a list operator receives a multi line lambda. Mixin multi and single line lambdas feels inconsistent.The text was updated successfully, but these errors were encountered: