dfmt icon indicating copy to clipboard operation
dfmt copied to clipboard

Chain break with template arguments

Open belka-ew opened this issue 5 years ago • 3 comments

 string main()
 {
-    return duration.total!"seconds".to!string;
+    return duration.total!"seconds"
+        .to!string;
 }

It doesn't seem to happen if the chain has only one !.

I hope it isn't already reported since there're some similar issues, similar, but still different.

belka-ew avatar Aug 24 '20 07:08 belka-ew

this is by design / how it was initially implemented, see https://github.com/dlang-community/dfmt/blob/58b2c6ebc620af1351821509b435c821cd175d90/src/dfmt/ast_info.d#L346

Maybe adding something like || (chainLength == 1 && totalChainLength > 3) || totalChainLength > 4 with a totalChainLength variable counting all unary expressions with u.identifierOrTemplateInstance set (no matter if template or not) could be what you want. However setting these thresholds would need more testing in bigger repositories to see how it affects them.

WebFreak001 avatar Aug 25 '20 06:08 WebFreak001

I'm a bit confused because it works differently with similar expressions.

For example this one is left as is:

string main()
{
    return duration.total("seconds").to!string;
}

(Same code, but "seconds" is a normal argument and not a template argument).

I see now, that even this is left as is:

string main()
{
    return duration.total!"seconds"().to!string;
}

(Just with () after "seconds")

I would be happy if it works with keep_line_breaks without breaking the line, because currently it doesn't.

belka-ew avatar Aug 25 '20 06:08 belka-ew

ufcs breaking only occurs once the line reaches some minimum length iirc

WebFreak001 avatar Aug 25 '20 07:08 WebFreak001