Skip to content

Commit 84eeea8

Browse files
authored
Add guidance for long if expression in fsharp. (#23897)
1 parent b54631d commit 84eeea8

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

docs/fsharp/style-guide/formatting.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,46 @@ else
892892
e4
893893
```
894894

895+
If a condition is long, place it on the next line with an extra indent.
896+
Align the `if` and the `then` keywords.
897+
898+
```fsharp
899+
if
900+
complexExpression a b && env.IsDevelopment()
901+
|| secondLongerExpression
902+
aVeryLongparameterNameOne
903+
aVeryLongparameterNameTwo
904+
aVeryLongparameterNameThree
905+
"""
906+
Multiline
907+
string
908+
"""
909+
then
910+
e1
911+
else
912+
e2
913+
```
914+
915+
If you have a condition that is this long, first consider refactoring it into a separate function and calling that function instead
916+
917+
```fsharp
918+
let condition () =
919+
complexExpression a b && env.IsDevelopment()
920+
|| secondLongerExpression
921+
aVeryLongparameterNameOne
922+
aVeryLongparameterNameTwo
923+
aVeryLongparameterNameThree
924+
"""
925+
Multiline
926+
string
927+
"""
928+
929+
if condition () then
930+
e1
931+
else
932+
e2
933+
```
934+
895935
### Pattern matching constructs
896936

897937
Use a `|` for each clause of a match with no indentation. If the expression is short, you can consider using a single line if each subexpression is also simple.

0 commit comments

Comments
 (0)