dart_style
dart_style copied to clipboard
Indentation with chained calls with long arguments is very confusing
I can't figure out what combination of commas to put in this code to make the formatting reasonable:
void assertThatImageLoadingSucceeds(NetworkImageWithRetry subject) {
subject
.load(
subject,
_ambiguate(PaintingBinding.instance)!.instantiateImageCodec,
)
.addListener(
ImageStreamListener(
expectAsync2((ImageInfo image, bool synchronousCall) {
expect(image.image.height, 1);
expect(image.image.width, 1);
}),
),
);
}
More cases that my friend reported to me 6 months ago, https://github.com/iota9star/mikan_flutter/blob/ae591e1de035f6b845acb11b2e00b634d85b9c2a/lib/internal/http_cache_manager.dart#L46 :
final Completer<File?> completer = Completer();
_httpCacheManager
._(
url,
cacheKey: cacheKey,
cacheDir: cacheDir,
headers: headers,
chunkEvents: chunkEvents,
cancelable: cancelable,
)
.then((value) {
completer.complete(value);
}).catchError((dynamic error, StackTrace stackTrace) {
completer.completeError(error, stackTrace);
}).whenComplete(() => _tasks.remove(url));
Yeah, those are both pretty bad. These are more cases where the formatting rules for argument lists with trailing commas interacts poorly with other formatting rules.
Wow, yeah. These examples really hit the limitations of the old formatter. I ran them through the forthcoming tall style and got:
void assertThatImageLoadingSucceeds(NetworkImageWithRetry subject) {
subject
.load(
subject,
_ambiguate(PaintingBinding.instance)!.instantiateImageCodec,
)
.addListener(
ImageStreamListener(
expectAsync2((ImageInfo image, bool synchronousCall) {
expect(image.image.height, 1);
expect(image.image.width, 1);
}),
),
);
}
And:
_httpCacheManager
._(
url,
cacheKey: cacheKey,
cacheDir: cacheDir,
headers: headers,
chunkEvents: chunkEvents,
cancelable: cancelable,
)
.then((value) {
completer.complete(value);
})
.catchError((dynamic error, StackTrace stackTrace) {
completer.completeError(error, stackTrace);
})
.whenComplete(() => _tasks.remove(url));
Those look worlds better to me.
That looks so much better!