You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose we add an option for consistent indentation style of all pattern matching branches.
The existing way of Fantomas deals with this problem is that it takes into account line length of an individual branch expression.
As a result of that, some branches may be split into multiple lines with indentation, while other branches are in single line.
I believe it would improve readability (at least in some cases) if all pattern matching branches were indented consistently.
Pros and Cons
The advantages of making this adjustment to Fantomas are:
long match expressions are more readable
The disadvantages of making this adjustment to Fantomas are:
short branches will be indented although they would have fit line width without indentation, so some may consider it unnecessary
Examples
Consider this initial source code:
letfromDomain(evt:InventoryEvent)=match evt with| InventoryCreated x ->
x |> InventoryCreatedMapper.fromDomain :> CqrsEventDto
| ItemInStock x ->
x |> ItemInStockMapper.fromDomain :> CqrsEventDto
| ItemWentOutOfStock x ->
x |> ItemWentOutOfStockMapper.fromDomain :> CqrsEventDto
lettoDomain(dto:CqrsEventDto)=match dto with|:? InventoryCreatedEvent as x ->
x
|> InventoryCreatedMapper.toDomain
|> Result.map InventoryEvent.InventoryCreated
|:? ItemInStockEvent as x ->
x
|> ItemInStockMapper.toDomain
|> Result.map InventoryEvent.ItemInStock
|:? ItemWentOutOfStockEvent as x ->
x
|> ItemWentOutOfStockMapper.toDomain
|> Result.map InventoryEvent.ItemWentOutOfStock
| x ->
raise (EventDtoMappingException $"Unknown event DTO type: {x.GetType().FullName}")
Fantomas 6.0 with default settings will produce following formatted code:
letfromDomain(evt:InventoryEvent)=match evt with| InventoryCreated x -> x |> InventoryCreatedMapper.fromDomain :> CqrsEventDto
| ItemInStock x -> x |> ItemInStockMapper.fromDomain :> CqrsEventDto
| ItemWentOutOfStock x -> x |> ItemWentOutOfStockMapper.fromDomain :> CqrsEventDto
lettoDomain(dto:CqrsEventDto)=match dto with|:? InventoryCreatedEvent as x ->
x
|> InventoryCreatedMapper.toDomain
|> Result.map InventoryEvent.InventoryCreated
|:? ItemInStockEvent as x -> x |> ItemInStockMapper.toDomain |> Result.map InventoryEvent.ItemInStock
|:? ItemWentOutOfStockEvent as x ->
x
|> ItemWentOutOfStockMapper.toDomain
|> Result.map InventoryEvent.ItemWentOutOfStock
| x -> raise (EventDtoMappingException $"Unknown event DTO type: {x.GetType().FullName}")
Note that the branch :? InventoryCreatedEvent is indented while the branch :? ItemInStockEvent is not indented.
I don't mind the changes in the 1st match in the formatted output, but to my eye 2nd match looks misaligned, it becomes even more apparent when more branches of mixed length are added to that match.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): M? (No idea TBH)
I propose we add an option for consistent indentation style of all pattern matching branches.
The existing way of Fantomas deals with this problem is that it takes into account line length of an individual branch expression.
As a result of that, some branches may be split into multiple lines with indentation, while other branches are in single line.
I believe it would improve readability (at least in some cases) if all pattern matching branches were indented consistently.
Pros and Cons
The advantages of making this adjustment to Fantomas are:
The disadvantages of making this adjustment to Fantomas are:
Examples
Consider this initial source code:
Fantomas 6.0 with default settings will produce following formatted code:
Note that the branch
:? InventoryCreatedEvent
is indented while the branch:? ItemInStockEvent
is not indented.I don't mind the changes in the 1st
match
in the formatted output, but to my eye 2ndmatch
looks misaligned, it becomes even more apparent when more branches of mixed length are added to thatmatch
.Extra information
Estimated cost (XS, S, M, L, XL, XXL): M? (No idea TBH)
Related suggestions: N/A
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: