[style-guide]: Multiline generic type parameters bracket alignment
- Dominant language
- F#
- Stars
- 557
- Forks
- 149
- Avg merge
- 4d 13h
- Merged PRs (30d)
- 2
Description
As discussed in https://github.com/fsprojects/fantomas/issues/2706 and https://github.com/fsprojects/fantomas/pull/2852, with the recent changes regarding multiline bracket formatting, multiline generic type parameters don't necessarily always follow the same guidelines, so we should formalize how they can/should be formatted.
For example, if using `Stroustrup` bracket style, you might expect
```fsharp
let private asJson (arm: IArmResource) =
arm.JsonModel
|> convertTo<{|
kind: string
properties: {| statisticsEnabled: bool |}
|}>
```
to be formatted like this:
```fsharp
let private asJson (arm: IArmResource) =
arm.JsonModel
|> convertTo<
{|
kind: string
properties: {| statisticsEnabled: bool |}
|}
>
```
However, the placement of the angle brackets can be problematic.
For example, if you have an application expression:
```fsharp
let bv = unbox 'b>> bf
```
And try to directly apply `Stroustrup` style to it:
```fsharp
let bv =
unbox<
Foo<
'innerContextLongLongLong,
'bb -> 'b
>
>
bf
```
This code is invalid. The compiler sees these as two separate statements. So short of updating the compiler, code in this style will need to have at least one additional space on the newline before the closing angle bracket.
```diff
let bv =
unbox<
Foo<
'innerContextLongLongLong,
'bb -> 'b
- >
+ >
- >
+ >
bf
```
Bikeshedding question: should this be the minimal change necessary (1 space)? Or should it be a multiplier of your `indent_size` (if you use 2 spaces, use 2 spaces)?
Also, it probably should be noted that truly "Aligned" angle bracket style doesn't work:
```fsharp
let private asJson (arm: IArmResource) =
arm.JsonModel
|> convertTo
<
{|
kind: string
properties: {| statisticsEnabled: bool |}
|}
>
```
Some users may expect that to work but it's invalid code. We should maybe update the style to mention this (if it's not there already).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.