dart_style
dart_style copied to clipboard
Better code formatting for flow controls in Maps
I recently stumbled upon this piece of code from a colleague of mine and had real problems at first to understand what is going on here:
One reason for sure was that I wasn't aware that we can use if
and for
not only inside Lists
but also for Maps
which is indeed a pretty cool feature :-) the bigger reason IMHO is that the way dartformat currently treats this makes it hard to spot where the key of the created/inserted pair is. To be honest I don't have a good idea of how to do this better. Maybe outdent the key?
Maybe @munificent has an idea of how to improve this.
Maybe the issue should be moved to: https://github.com/dart-lang/dart_style/issues ?
Oh definitely, I didn't know that there is a separate repository for the formatted. So please anyone who can move an issue please move it there?
I agree! I would like to insert a new line after a conditional or loop statement and indent the key. Here's an example of how it could look:
final current = {
if (true) 'a': 1,
for (final i in [1, 2, 3]) 'b$i': i,
for (final nested in foo1)
for (final i in nested) 'c$i': i,
for (final nested in foo2) ...nested,
};
final proposed = {
if (true)
'a': 1,
for (var i in [1, 2, 3])
'b$i': i,
for (final nested in foo1)
for (final i in nested)
'c$i': i,
for (final nested in foo2)
...nested,
};