Skip to content

Commit f160bf3

Browse files
randragclaude
andcommitted
Apply self-formatting to alignment helpers and tests
Bringing CodePrinter.fs and the new Agrico test files in line with the fork's CheckFormat stage. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c98602d commit f160bf3

3 files changed

Lines changed: 30 additions & 32 deletions

File tree

src/Fantomas.Core.Tests/Agrico/AgricoMatchArrowAlignmentTests.fs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ let f x =
3636
| LongCaseName -> 3
3737
| VeryLongCaseName -> 4
3838
"""
39-
{ config with MatchArrowAlignment = true }
39+
{ config with
40+
MatchArrowAlignment = true }
4041
|> prepend newline
4142
|> should
4243
equal
@@ -57,7 +58,8 @@ let f x =
5758
match x with
5859
| A -> 1
5960
"""
60-
{ config with MatchArrowAlignment = true }
61+
{ config with
62+
MatchArrowAlignment = true }
6163
|> prepend newline
6264
|> should
6365
equal
@@ -79,7 +81,8 @@ let f x =
7981
| LongCaseName -> 3
8082
| C -> 4
8183
"""
82-
{ config with MatchArrowAlignment = true }
84+
{ config with
85+
MatchArrowAlignment = true }
8386
|> prepend newline
8487
|> should
8588
equal
@@ -132,7 +135,8 @@ let f =
132135
| Bb -> 2
133136
| LongCaseName -> 3
134137
"""
135-
{ config with MatchArrowAlignment = true }
138+
{ config with
139+
MatchArrowAlignment = true }
136140
|> prepend newline
137141
|> should
138142
equal
@@ -156,7 +160,8 @@ let f x =
156160
| LongCaseName s -> 0
157161
| C -> 0
158162
"""
159-
{ config with MatchArrowAlignment = true }
163+
{ config with
164+
MatchArrowAlignment = true }
160165
|> prepend newline
161166
|> should
162167
equal
@@ -178,7 +183,8 @@ let f x =
178183
| Bb -> 2
179184
| LongCaseName -> 3
180185
"""
181-
{ config with MatchArrowAlignment = false }
186+
{ config with
187+
MatchArrowAlignment = false }
182188
|> prepend newline
183189
|> should
184190
equal

src/Fantomas.Core.Tests/Agrico/AgricoUnionCaseAlignmentTests.fs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ type Foo =
3434
| LongCaseName of bool
3535
| VeryLongCaseName of obj
3636
"""
37-
{ config with UnionCaseAlignment = true }
37+
{ config with
38+
UnionCaseAlignment = true }
3839
|> prepend newline
3940
|> should
4041
equal
@@ -80,7 +81,8 @@ type Foo =
8081
| LongCaseName of bool
8182
| C of obj
8283
"""
83-
{ config with UnionCaseAlignment = true }
84+
{ config with
85+
UnionCaseAlignment = true }
8486
|> prepend newline
8587
|> should
8688
equal
@@ -104,7 +106,8 @@ type Foo =
104106
| A of int
105107
| Bbb of string
106108
"""
107-
{ config with UnionCaseAlignment = true }
109+
{ config with
110+
UnionCaseAlignment = true }
108111
|> prepend newline
109112
|> should
110113
equal
@@ -125,7 +128,8 @@ type Foo =
125128
| LongCaseName
126129
| VeryLongCaseName
127130
"""
128-
{ config with UnionCaseAlignment = true }
131+
{ config with
132+
UnionCaseAlignment = true }
129133
|> prepend newline
130134
|> should
131135
equal
@@ -261,7 +265,8 @@ type Foo =
261265
| LongCaseName of bool
262266
| VeryLongCaseName of obj
263267
"""
264-
{ config with UnionCaseAlignment = false }
268+
{ config with
269+
UnionCaseAlignment = false }
265270
|> prepend newline
266271
|> should
267272
equal

src/Fantomas.Core/CodePrinter.fs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4140,8 +4140,7 @@ let private groupUnionCasesByBlankLines (cases: UnionCaseNode list) : UnionCaseN
41404140
// that have `of`. Cases without `of` are skipped — they don't influence
41414141
// the alignment column. Returns 0 if no case in the group has `of`.
41424142
let private unionCaseGroupWidthTarget (group: UnionCaseNode list) : int =
4143-
let widths =
4144-
group |> List.filter unionCaseHasOf |> List.map unionCaseIdentWidth
4143+
let widths = group |> List.filter unionCaseHasOf |> List.map unionCaseIdentWidth
41454144

41464145
if List.isEmpty widths then 0 else List.max widths
41474146

@@ -4187,8 +4186,7 @@ let private genUnionCaseFieldsInlineFirst (fields: FieldNode list) (ctx: Context
41874186
let firstFieldCol = ctx.Column
41884187

41894188
let renderRest =
4190-
col sepNone restFields (fun f ->
4191-
sepNln +> addFixedSpaces firstFieldCol +> !-"* " +> genField f)
4189+
col sepNone restFields (fun f -> sepNln +> addFixedSpaces firstFieldCol +> !-"* " +> genField f)
41924190

41934191
(genField firstField +> renderRest) ctx
41944192

@@ -4310,8 +4308,7 @@ let private clausePrefixWidth (node: MatchClauseNode) (ctx: Context) : int =
43104308
| Some barNode -> genSingleTextNodeWithSpaceSuffix sepSpace barNode
43114309
| None -> sepBar
43124310

4313-
let genWhen =
4314-
optSingle (fun e -> sepSpace +> !-"when " +> genExpr e) node.WhenExpr
4311+
let genWhen = optSingle (fun e -> sepSpace +> !-"when " +> genExpr e) node.WhenExpr
43154312

43164313
let prefix = genBar +> genPatInClause node.Pattern +> genWhen
43174314
let dummy = ctx.WithDummy(prefix, keepPageWidth = false)
@@ -4328,17 +4325,12 @@ let private clauseFitsInline (node: MatchClauseNode) (ctx: Context) : bool =
43284325
| Some barNode -> genSingleTextNodeWithSpaceSuffix sepSpace barNode
43294326
| None -> sepBar
43304327

4331-
let genWhen =
4332-
optSingle (fun e -> sepSpace +> !-"when " +> genExpr e) node.WhenExpr
4328+
let genWhen = optSingle (fun e -> sepSpace +> !-"when " +> genExpr e) node.WhenExpr
43334329

43344330
let genArrowAndBody =
4335-
sepSpace
4336-
+> genSingleTextNode node.Arrow
4337-
+> sepSpace
4338-
+> genExpr node.BodyExpr
4331+
sepSpace +> genSingleTextNode node.Arrow +> sepSpace +> genExpr node.BodyExpr
43394332

4340-
let inner =
4341-
genBar +> genPatInClause node.Pattern +> genWhen +> genArrowAndBody
4333+
let inner = genBar +> genPatInClause node.Pattern +> genWhen +> genArrowAndBody
43424334

43434335
let dummy = ctx.WithDummy(inner, keepPageWidth = true)
43444336

@@ -4354,8 +4346,7 @@ let private genClauseAlignedInline (widthTarget: int) (node: MatchClauseNode) =
43544346
| Some barNode -> genSingleTextNodeWithSpaceSuffix sepSpace barNode
43554347
| None -> sepBar
43564348

4357-
let genWhen =
4358-
optSingle (fun e -> sepSpace +> !-"when " +> genExpr e) node.WhenExpr
4349+
let genWhen = optSingle (fun e -> sepSpace +> !-"when " +> genExpr e) node.WhenExpr
43594350

43604351
let genPaddedClause (ctx: Context) =
43614352
let startCol = ctx.Column
@@ -4386,11 +4377,7 @@ let private genMaybeAlignedClauses (cfg: FormatConfig) (clauses: MatchClauseNode
43864377
// recursively re-enter genMaybeAlignedClauses for any nested
43874378
// match — multiplying work exponentially in clause-nesting depth.
43884379
// The dummy run only needs upstream layout for the measurement.
4389-
if
4390-
not cfg.MatchArrowAlignment
4391-
|| List.isEmpty clauses
4392-
|| ctx.WriterModel.IsDummy
4393-
then
4380+
if not cfg.MatchArrowAlignment || List.isEmpty clauses || ctx.WriterModel.IsDummy then
43944381
let lastIndex = clauses.Length - 1
43954382

43964383
(coli sepNln clauses (fun idx clause ->

0 commit comments

Comments
 (0)