Avoid chopping single trailing lambda#1876
Conversation
belav
left a comment
There was a problem hiding this comment.
The code looks good but I do disagree with the simple lambdas breaking. If you can make that change I'll redo the csharpier-repos PR to see if there are any edgecases that need to be handled.
Thanks for taking this on!
| bodyIsBraced ? Doc.Null : Doc.SoftLine | ||
| ); | ||
|
|
||
| return Doc.ConditionalGroup(wrap, wrap, chop); |
There was a problem hiding this comment.
I think this should just be return Doc.ConditionalGroup(wrap, chop);
Passing the same doc twice just ends up doing more work in the case where chop is what is used.
| CallMethod(CallAnotherMethod_________________(), () => | ||
| CallAnotherMethod_________________() | ||
| ); |
There was a problem hiding this comment.
I don't agree with this breaking this way, and prettier also avoids breaking this.
// input & expected output
var antiforgeryMiddleware = new AntiforgeryMiddleware(
antiforgeryService.Object,
hc => Task.CompletedTask
);
// this pr
var antiforgeryMiddleware = new AntiforgeryMiddleware(antiforgeryService.Object, hc =>
Task.CompletedTask
);This is what I think should be breaking, and prettier does it this way. The pr works this way currently but I don't see a test for it.
// input & expected output
Assert.Collection(receiveAuthStateDiff.Edits, edit =>
{
Assert.Equal(RenderTreeEditType.PrependFrame, edit.Type);
AssertFrame.Text(
batch.ReferenceFrames[edit.ReferenceFrameIndex],
"Authenticated: True; Name: Bert; Pending: False; Renders: 1"
);
});I just did a quick scan of https://github.com/belav/csharpier-repos/pull/172/changes and ran into that first case right away.
Description
Adds in the ability to avoid chopping single trailing lambdas when the argument list up to and including the "=>" symbol doesn't need to be chopped.
This would take a snippet of code like
And turn it into this (assuming configured line length isn't exceeded):
Without breaking directives or comments:
And avoids chopping when the lambda is not the last argument or there are multiple arguments:
Related Issue
Closes #1865
Checklist
varthis.