dotnet / dotnet/docs

F# style guide question - multiline expression in match or if expression

Open
#26,507 16 comments 0 reactions 0 assignees View on GitHub
dotnet-fsharp/svc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
15h 21m
Merged PRs (30d)
370

Description

Hello @dsyme ,

Following up on https://github.com/fsprojects/fantomas/issues/1915, I'd like to verify how you see the formatting of long (say multiline) expressions inside `if/then/else` of `match/with`.

I have two questions here:
- Are the rules the same for `if/then` as they are for `match/with`? I always assumed so to remain consistent.
- The docs for `if/then/else` mention
![image](https://user-images.githubusercontent.com/2621499/137264344-5b45cd3e-7d78-4d8b-82cf-da47aa1e7fe3.png)

What is long? Would any multiline expression fit the bill here?
Example
```fsharp
if directoryRouter.GetIdentity()
|> self.ServerDescriptors.TryFind then
CircuitNodeDetail.FastCreate
else
self.ConvertToCircuitNodeDetail serverDescriptor
```

Should it be

```fsharp
if
directoryRouter.GetIdentity ()
|> self.ServerDescriptors.TryFind then
CircuitNodeDetail.FastCreate
else
self.ConvertToCircuitNodeDetail serverDescriptor
```
?

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 8c09996f-24ac-cf39-ef43-d7909cbc2b89
* Version Independent ID: 1efdd523-8552-6421-e149-74f76826ef8f
* Content: [F# code formatting guidelines](https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting#formatting-tuples)
* Content Source: [docs/fsharp/style-guide/formatting.md](https://github.com/dotnet/docs/blob/main/docs/fsharp/style-guide/formatting.md)
* Product: **dotnet-fsharp**
* GitHub Login: @cartermp
* Microsoft Alias: **dotnetcontent**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.