-
Notifications
You must be signed in to change notification settings - Fork 143
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
[style-guide] Chain of (fluent) calls #688
Comments
Hello Sergey, Thanks for bringing this up, this topic can definitely be improved. What should happen with long prefixes? Microsoft.FSharp.Reflection.FSharpType.GetUnionCases(typeof<option<option<unit>>>.GetGenericTypeDefinition().MakeGenericType(t)).Assembly
System
.Diagnostics
.FileVersionInfo
.GetVersionInfo(
System
.Reflection
.Assembly
.GetExecutingAssembly()
.Location
)
.FileVersion There are some offset rules when there is a lambda involved: let getColl3 =
GetCollection(fun _ parser ->
let x = 3
x)
.Foo configuration
.MinimumLevel.Debug()
.WriteTo.Logger(fun loggerConfiguration ->
loggerConfiguration
.Enrich.WithProperty("host", Environment.MachineName)
.Enrich.WithProperty("user", Environment.UserName)
.Enrich.WithProperty("application", context.HostingEnvironment.ApplicationName)
|> ignore
) |
Hello, I would like to take a stab at this. It would be great if this area was improved in the style guide and Fantomas. DefinitionsFirst of I'd like to define a chain as a sequence of links separated by dots.
And a RulesetIf a chain fits on the maximum threshold, it should be on a single line: A.B().A When a chain no longer fits, it becomes multiline. First-line examples: A.A.A
.rest...
A<'a>.A.A
.rest...
A.[0].A
.rest... The rest of the chain would be indented: A.A.A
.B()
.C(c) Every link that is not a simple link would introduce a new line. A.A.A
.B()
.A.C(c)
.A.A.D(fun d -> d)
.A When an application does not fit on the remainder of the line it goes multiline similar as if it were an application outside of a chain: A.A.A
.C(
c1,
c2,
c3,
c4
)
.D(fun d ->
// comment
d
) The inner expression inside the parentheses is indented further. When that expression is a lambda only the body of the lambda is indented further. The application is considered multiline purely on evaluating its own content. // OK ✅
A
.C(short)
.C(
long1,
long2,
long3
)
// Not OK ❌
A
.C(
short
)
.C(
long1,
long2,
long3
) RationaleThe reasoning behind this suggestion is the following:
ExamplesSee fsprojects/fantomas#2696, you can look at the test files to see what the effect is. Equinox.MemoryStore
.Resolver(store, FsCodec.Box.Codec.Create(), fold, initial)
configuration.MinimumLevel
.Debug()
.WriteTo.Logger (fun loggerConfiguration ->
loggerConfiguration.Enrich
.WithProperty("host", Environment.MachineName)
.Enrich.WithProperty("user", Environment.UserName)
.Enrich.WithProperty (
"application",
context.HostingEnvironment.ApplicationName
)
System.Diagnostics.FileVersionInfo
.GetVersionInfo(
System.Reflection.Assembly
.GetExecutingAssembly()
.Location
) LimitationsNot everything with a dot in it would be considered a chain. |
This looks so good |
I very much like the principled groupings/naming of the different kinds of applications/fluent calls. That makes it much easier to determine and talk about a set of rules for the different scenarios. I agree with Don - this looks amazing! |
Hello @dsyme, I tried this out on some more code bases and the results were favourable. |
Style guide PR: dotnet/docs#33524 |
This is available in Fantomas v5.2, the issue can be closed. |
We faced an issue that current version of Fantomas format one liner
like this
In my opinion such formation is very verbose and @nojaf mentioned that there is no guidance in style guide how to format such code.
In my opinion formatting should be similar to pipeline expressions and look at least like this
The text was updated successfully, but these errors were encountered: