Skip to content

Commit 0007934

Browse files
committed
Don't put a space before a prefix operator, unless we have to. (#3134)
* Don't put a space before a prefix operator, unless we have to. * Add feedback from code review * Only add space to measure when constant has sign. * Remove unnecessary open
1 parent 74411a5 commit 0007934

11 files changed

+244
-156
lines changed

Diff for: src/Fantomas.Core.Tests/ControlStructureTests.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ let genPropertyWithGetSet astContext (b1, b2) rangeOfMember =
644644
genPreXmlDoc px
645645
+> genAttributes astContext ats
646646
+> genMemberFlags astContext mf1
647-
+> ifElse isInline (!- "inline ") sepNone
647+
+> ifElse isInline (!-"inline ") sepNone
648648
+> opt sepSpace ao genAccess
649649
650650
assert (ps1 |> Seq.map fst |> Seq.forall Option.isNone)

Diff for: src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
<Compile Include="BeginEndTests.fs" />
135135
<Compile Include="NullnessTests.fs" />
136136
<Compile Include="AutoPropertiesTests.fs" />
137+
<Compile Include="PrefixTests.fs" />
137138
</ItemGroup>
138139
<ItemGroup>
139140
<ProjectReference Include="..\Fantomas.Core\Fantomas.Core.fsproj" />

Diff for: src/Fantomas.Core.Tests/InterpolatedStringTests.fs

-14
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,6 @@ $\"\"\"one: {1}<
165165
>two: {2}\"\"\"
166166
"
167167

168-
[<Test>]
169-
let ``prefix application, 1414`` () =
170-
formatSourceString
171-
"""
172-
!- $".{s}"
173-
"""
174-
config
175-
|> prepend newline
176-
|> should
177-
equal
178-
"""
179-
!- $".{s}"
180-
"""
181-
182168
[<Test>]
183169
let ``format in FillExpr, 1549`` () =
184170
formatSourceString

Diff for: src/Fantomas.Core.Tests/LambdaTests.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ let genMemberFlagsForMemberBinding astContext (mf: MemberFlags) (rangeOfBindingA
354354
| Token { TokenInfo = { TokenName = "MEMBER" } } -> r.StartLine = rangeOfBindingAndRhs.StartLine
355355
356356
| _ -> false)
357-
|> Option.defaultValue (!- "override ")
357+
|> Option.defaultValue (!-"override ")
358358
<| ctx)
359359
<| ctx
360360
"""

Diff for: src/Fantomas.Core.Tests/LetBindingTests.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ let internal sepSpace =
13421342
then
13431343
ctx
13441344
else
1345-
(!- " ") ctx
1345+
(!-" ") ctx
13461346
"""
13471347

13481348
[<Test>]

Diff for: src/Fantomas.Core.Tests/MultiLineLambdaClosingNewlineTests.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ let expr =
268268
es
269269
(fun e ->
270270
match e with
271-
| Paren(_, Lambda _, _) -> !- "lambda"
271+
| Paren(_, Lambda _, _) -> !-"lambda"
272272
| _ -> genExpr astContext e
273273
)
274274
"""

Diff for: src/Fantomas.Core.Tests/OperatorTests.fs

-117
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,6 @@ open FsUnit
55
open Fantomas.Core.Tests.TestHelpers
66
open Fantomas.Core
77

8-
[<Test>]
9-
let ``should format prefix operators`` () =
10-
formatSourceString
11-
"""let x = -y
12-
let z = !!x
13-
"""
14-
config
15-
|> should
16-
equal
17-
"""let x = -y
18-
let z = !!x
19-
"""
20-
21-
[<Test>]
22-
let ``should keep triple ~~~ operator`` () =
23-
formatSourceString
24-
"""x ~~~FileAttributes.ReadOnly
25-
"""
26-
config
27-
|> should
28-
equal
29-
"""x ~~~FileAttributes.ReadOnly
30-
"""
31-
32-
[<Test>]
33-
let ``should keep single triple ~~~ operator`` () =
34-
formatSourceString
35-
"""~~~FileAttributes.ReadOnly
36-
"""
37-
config
38-
|> should
39-
equal
40-
"""~~~FileAttributes.ReadOnly
41-
"""
42-
438
[<Test>]
449
let ``should keep parens around ? operator definition`` () =
4510
formatSourceString
@@ -62,17 +27,6 @@ let ``should keep parens around ?<- operator definition`` () =
6227
"""let (?<-) f s = f s
6328
"""
6429

65-
[<Test>]
66-
let ``should keep parens around !+ prefix operator definition`` () =
67-
formatSourceString
68-
"""let (!+) x = Include x
69-
"""
70-
config
71-
|> should
72-
equal
73-
"""let (!+) x = Include x
74-
"""
75-
7630
[<Test>]
7731
let ``should keep parens around ++ infix operator definition`` () =
7832
formatSourceString
@@ -474,19 +428,6 @@ let result =
474428
(typ.GetInterface(typeof<System.Collections.IEnumerable>.FullName) = null)
475429
"""
476430

477-
[<Test>]
478-
let ``operator before verbatim string add extra space, 736`` () =
479-
formatSourceString
480-
"""Target M.Tools (fun _ -> !! @"Tools\Tools.sln" |> rebuild)
481-
"""
482-
config
483-
|> prepend newline
484-
|> should
485-
equal
486-
"""
487-
Target M.Tools (fun _ -> !! @"Tools\Tools.sln" |> rebuild)
488-
"""
489-
490431
[<Test>]
491432
let ``function call before pipe operator, 754`` () =
492433
formatSourceString
@@ -1178,42 +1119,6 @@ module Foo =
11781119
| false -> id)
11791120
"""
11801121

1181-
let operator_application_literal_values =
1182-
[ "-86y"
1183-
"86uy"
1184-
"-86s"
1185-
"86us"
1186-
"-86"
1187-
"-86l"
1188-
"86u"
1189-
"86ul"
1190-
"-123n"
1191-
"0x00002D3Fun"
1192-
"-86L"
1193-
"86UL"
1194-
"-4.41F"
1195-
"-4.14"
1196-
"-12456I"
1197-
"-0.7833M"
1198-
"'a'"
1199-
"\"text\""
1200-
"'a'B"
1201-
"\"text\"B" ]
1202-
1203-
[<TestCaseSource("operator_application_literal_values")>]
1204-
let ``operators maintain spacing from literal values`` (literalValue: string) =
1205-
formatSourceString
1206-
$"""
1207-
let subtractTwo = + %s{literalValue}
1208-
"""
1209-
config
1210-
|> prepend newline
1211-
|> should
1212-
equal
1213-
$"""
1214-
let subtractTwo = + %s{literalValue}
1215-
"""
1216-
12171122
[<Test>]
12181123
let ``qualified name to active pattern, 1937`` () =
12191124
formatSourceString
@@ -1515,25 +1420,3 @@ let allDecls =
15151420
@+ iimplsLs
15161421
@+ ctorLs
15171422
"""
1518-
1519-
[<Test>]
1520-
let ``adding space after prefix operator breaks code, 2796`` () =
1521-
formatSourceString
1522-
"""
1523-
let inline (~%%) id = int id
1524-
1525-
let f a b = a + b
1526-
1527-
let foo () = f %%"17" %%"42"
1528-
"""
1529-
config
1530-
|> prepend newline
1531-
|> should
1532-
equal
1533-
"""
1534-
let inline (~%%) id = int id
1535-
1536-
let f a b = a + b
1537-
1538-
let foo () = f %%"17" %%"42"
1539-
"""

0 commit comments

Comments
 (0)