I have some F# code that calls a method written in C# with lots of parameters.
In order to make things legible I use named parameters when calling the method:
let request = Models.UserService.CreateUserRequest(
email = "[email protected]",
password = "password",
title = "title",
firstname = "firstname",
lastname = "lastname",
nickname = "nickname",
locale = "locale",
birthDate = "birthdate",
currency = "USD",
ipAddress = "127.0.0.1",
address = address,
mobilePhone = "+1 123 456 7890"
)
However I get a warning about the indentation:
warning FS0058: Possible incorrect indentation: this token is offside of context started at position (30:19). Try indenting this token further or using standard formatting conventions.
Obviously if I do not use named parameters or put everything in a single line, the warning disappears. But I want to format this in a way that is legible.
Is there a way to format a method call on multiple lines in F# without having a warning?
The formal description of Lightweight Syntax is contained in the F# language spec, and the particular feature you are after is called Offside Context. This will allow you to reduce indentation to the column of the last context plus one or more additional columns. The Offside Context will be encountered immediately after the =
assignment in a Let
context, as well as after the opening paren in a Paren
context.
In effect, you can have an indentation like this:
let request =
Models.UserService.CreateUserRequest(
email = "[email protected]",
password = "password",
... )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With