-
Notifications
You must be signed in to change notification settings - Fork 121
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
Redundant newline with shorthand (=>) #785
Comments
Found an even more extreme example:
this should not wrap. |
@Hixie, what output would you expect here? I don't have any intuition for how Flutter-style block formatting should interact with |
I would expect the first to become: static HandlerResponse<RouteState> handleRouteReplaced(
ReplaceRoute action,
RouteState state,
) {
return HandlerResponse.updateOnly(
state.copy(active: action.route, history: state.history),
);
} ...and the second to become: @override
Future<void> report({
String tag,
String message,
}) => Future.value(null); ...or, if it fits: @override
Future<void> report({ String tag, String message }) => Future.value(null); |
The first example has a multi-line |
by turning it into a block with a return statement. |
I think that would be incompatible with the |
That's why our
|
I guess maybe I'm not being clear enough. If you were an automated formatter that was only able to make whitespace changes to a given piece of code, what would you do with that code? |
I would reject the premise of the question. |
So should I just close this bug then? I don't know how to take action on it. |
Do issues of distaste with |
There are definitely many many multi-line This issue is about combining:
|
I don't know, this wasn't a bug I filed. I did file #452 back in 2015, which was the bug requesting that we reject the premise that the formatter be artificially limited to only changing whitespace and instead also change things like switching between |
OK. Having dartfmt automatically switch between All that means I can't make that change unilaterally or any time soon, if ever. If you don't have any suggestions for how to format the code in this bug better while only changing the whitespace then I guess I'll just leave it open and if I get time maybe I'll try to do something. |
An impactful change, one might say.
I have no data to say whether people would want this one way or the other. The argument that "if they chose to write
SGTM. I don't have any suggestions for how to format this code under those constraints; doing so would violate our style guide so we try to avoid doing it at all. |
If the magnitude is large, all the more important to make sure the sign bit is actually positive. |
If this code snippet is not formattable into a nice looking code via the Style guidelines, they are the ones needing a change. You can't build a car that can't go up hills and then blame it on the hill. |
It is. The Flutter style guide says the way you format that is you change it to a block with a return. |
The forthcoming tall style produces the desired output in both of these examples now: class C {
static HandlerResponse<RouteState> handleRouteReplaced(
ReplaceRoute action,
RouteState state,
) => HandlerResponse.updateOnly(
state.copy(active: action.route, history: state.history),
);
} And: class C {
@override
Future<void> report({
String tag,
String messageVeryLongParameterToForceSplit,
}) => Future.value(null);
} |
I guess this is the inverse from #721.
Actual Output:
Expected output:
This does not happen when using regular braces instead of the shorthand, and only when the trailing comma has been added to collapse the overflowing method header (e.g.
void hello() => doThat()
formats correctly).The text was updated successfully, but these errors were encountered: