F# style guide concerning do! indents + docs issue
- Dominant language
- No language data
- Stars
- 4.8k
- Forks
- 6.1k
- Avg merge
- 19h 10m
- Merged PRs (30d)
- 268
Description
### Type of issue
Other (describe below)
### Description
This ticket pertains to the F# code style guide and the linked documentation article.
The article says:
> Here's an example with do! using two spaces of indentation (because with do! there is coincidentally no difference between the approaches when using four spaces of indentation):
```fsharp
// ✔️ OK
async {
let! foo =
fooBarBaz
|> loremIpsumDolorSitAmet
|> theQuickBrownFoxJumpedOverTheLazyDog
do!
fooBarBaz
|> loremIpsumDolorSitAmet
|> theQuickBrownFoxJumpedOverTheLazyDog
}
```
```fsharp
// ❌ Not OK - notice the "do!" expression is indented two spaces more than the `let!` expression
async {
let! foo =
fooBarBaz
|> loremIpsumDolorSitAmet
|> theQuickBrownFoxJumpedOverTheLazyDog
do! fooBarBaz
|> loremIpsumDolorSitAmet
|> theQuickBrownFoxJumpedOverTheLazyDog
}
```
*My comments:*
There is a difference when using 4 spaces, because `do! ` works out to be exactly 4 characters.
The "bad example" becomes aligned and takes up less space:
```fsharp
async {
let! foo =
fooBarBaz
|> loremIpsumDolorSitAmet
|> theQuickBrownFoxJumpedOverTheLazyDog
do! fooBarBaz
|> loremIpsumDolorSitAmet
|> theQuickBrownFoxJumpedOverTheLazyDog
} |> ignore
```
I have encountered this issue when working with async and other CTES. The new lines inserted after do! don't affect alignment and reduce information density.
Here's an abbreviated version of some of my code. It's formatted by Fantomas with default settings.
```fsharp
// [...]
match relatedParent with
| Some parent ->
do!
writeRelated
httpClient
host
ctx
siteId
targetId
(cast ctx)
[| parent.Id |]
| _ -> ()
do!
writeRelated
httpClient
host
"en"
do!
writeRelated
httpClient
host
"en"
if someRelatedDataVals.Length > 0 then
do!
writeRelated
httpClient
host
"en"
dataCxt
siteId
do!
publish httpClient host "en" scope siteId targetId
|> AsyncResult.ignore
```
Here's how the same code would look like with the change.
```fsharp
// [...]
match relatedParent with
| Some parent ->
do! writeRelated
httpClient
host
ctx
siteId
targetId
(cast ctx)
[| parent.Id |]
| _ -> ()
do! writeRelated
httpClient
host
"en"
do! writeRelated
httpClient
host
"en"
if someRelatedDataVals.Length > 0 then
do! writeRelated
httpClient
host
"en"
dataCxt
siteId
do! publish httpClient host "en" scope siteId targetId
|> AsyncResult.ignore
```
### Page URL
https://learn.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting
### Content source URL
https://github.com/dotnet/docs/blob/main/docs/fsharp/style-guide/formatting.md
### Document Version Independent Id
1efdd523-8552-6421-e149-74f76826ef8f
### Article author
@KathleenDollard
### Metadata
* ID: 8c09996f-24ac-cf39-ef43-d7909cbc2b89
* Service: **dotnet-fsharp**
Contributor guide
Assessment
This issue has not been assessed yet.