-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Consider - keep Field.Method()
on the same line when breaking long method chain
#1010
Comments
This formatting only changed recently. Previously there was logic that kept properties and methods on the same line at times, which is how prettier formats. We had some discussion about it on discord, and it does feel a bit odd to treat properties differently than methods. var loggerConfiguration = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithProperty("key", "value")
.Enrich.WithProperty("key", "value")
.Enrich.WithProperty("key", "value")
.Enrich.WithProperty("key", "value")
.WriteTo.Console(outputTemplate: "template");
// vs
var loggerConfiguration = new LoggerConfiguration()
.Enrich()
.FromLogContext()
.Enrich()
.WithProperty("key", "value")
.Enrich()
.WithProperty("key", "value")
.Enrich()
.WithProperty("key", "value")
.Enrich()
.WithProperty("key", "value")
.WriteTo()
.Console(outputTemplate: "template"); But I do think your first few examples look better without the breaks. The var loggerConfiguration = new LoggerConfiguration()
.EnrichFromLogContext()
.EnrichWithProperty("key", "value")
.EnrichWithProperty("key", "value")
.EnrichWithProperty("key", "value")
.EnrichWithProperty("key", "value")
.WriteToConsole(outputTemplate: "template"); I think it is worth considering - for a single property call followed by a method call, keep them on the same line. The last example I do prefer the actual version, but maybe something like this would work. There is an issue somewhere around breaking the chain before breaking the method call. if (
_httpContextAccessor.HttpContext != null
&& _httpContextAccessor.HttpContext.Request.Headers
.TryGetValue("my-header", out var value)
)
{
return value;
} |
Same here. I guess it was more of a 'counter' example. |
Another example from #1043. Maybe it is best to go back to the way this was, I don't think there were any complaints about it previously.
|
Will you consider reverting this in a 0.26.x release? |
closes #1010 # Conflicts: # Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChains.test
That was.... way easier that I was thinking it would be. It was mixed in with other changes and was worried it would take more work to undo it. I'll have it out in a 0.26.7 soonish. |
closes #1010 # Conflicts: # Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChains.test
closes #1010 # Conflicts: # Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChains.test
closes #1010 # Conflicts: # Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChains.test
I came across this when working with fluent APIs, like
Serilog.LoggerConfiguration
andFluentAssertions
.I understand you need to insert the line breaks somewhere, but if you have
Field.Method()
, orField.Field.Method()
etc. it makes sense to keep them on the same line? (And only insert the line break after a method call?) Thoughts?I guess this breaks if you have
Field.Field.Field.Field...
such that it overflows the line width, but I feel that would be as rare as a variable name taking up the entire width (don't have data to back that up sorry).Few examples:
configuring Serilog logger
Expected:
Actual:
using FluentAssertions on a
List<string>
Expected:
Actual:
using
IHttpContextAccessor
in .NETExpected:
Actual:
The text was updated successfully, but these errors were encountered: