Skip to content

Commit a67f3a3

Browse files
authored
Support GR very long member definitions (#957)
* Format GR style long member definition with return type. * Format long members without return type the GR way. * Format long constructors the GR way. * Remove unnecessary ``new`` check * Bump to alpha-013
1 parent cda1c47 commit a67f3a3

File tree

9 files changed

+336
-47
lines changed

9 files changed

+336
-47
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
### 4.0.0-alpha-012 - 06/2020
1+
### 4.0.0-alpha-013 - 07/2020
22
* WIP for [#705](https://github.com/fsprojects/fantomas/issues/705)
3-
* FCS 36
3+
* FCS 36.0.3
44
* Replaced json configuration with .editorconfig
55

66
### 3.3.0 - 02/2020

src/Fantomas.CoreGlobalTool.Tests/Fantomas.CoreGlobalTool.Tests.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<GenerateProgramFile>false</GenerateProgramFile>
7-
<Version>4.0.0-alpha-012</Version>
7+
<Version>4.0.0-alpha-013</Version>
88
<NoWarn>FS0988</NoWarn>
99
</PropertyGroup>
1010
<ItemGroup>

src/Fantomas.CoreGlobalTool/Fantomas.CoreGlobalTool.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<ToolCommandName>fantomas</ToolCommandName>
66
<PackAsTool>True</PackAsTool>
7-
<Version>4.0.0-alpha-012</Version>
7+
<Version>4.0.0-alpha-013</Version>
88
<AssemblyName>fantomas-tool</AssemblyName>
99
</PropertyGroup>
1010
<ItemGroup>

src/Fantomas.Tests/Fantomas.Tests.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="..\netfx.props" />
33
<PropertyGroup>
4-
<Version>4.0.0-alpha-012</Version>
4+
<Version>4.0.0-alpha-013</Version>
55
<NoWarn>FS0988</NoWarn>
66
<TargetFramework>netcoreapp3.1</TargetFramework>
77
</PropertyGroup>

src/Fantomas.Tests/TypeDeclarationTests.fs

Lines changed: 171 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,8 @@ let ``member with one long parameter and no return type, 850`` () =
12171217
|> prepend newline
12181218
|> should equal """
12191219
type SomeType =
1220-
static member SomeMember loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
1220+
static member SomeMember loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1
1221+
=
12211222
printfn "a"
12221223
"b"
12231224
"""
@@ -1235,11 +1236,13 @@ let ``multiple members with one long parameter`` () =
12351236
|> prepend newline
12361237
|> should equal """
12371238
type SomeType =
1238-
static member SomeMember loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1 =
1239+
static member SomeMember loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1
1240+
=
12391241
printfn "a"
12401242
"b"
12411243
1242-
static member Serialize(loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2: SomeType) =
1244+
static member Serialize(loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong2: SomeType)
1245+
=
12431246
Encode.string v.Meh
12441247
12451248
static member Deserialize(loooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnnnnnnnnnnnngggggggggggJsonVaaaaalueeeeeeeeeeeeeeee)
@@ -1472,3 +1475,168 @@ type TestType =
14721475
// Some more comments
14731476
private { Foo: int }
14741477
"""
1478+
1479+
[<Test>]
1480+
let ``alternative long member definition`` () =
1481+
formatSourceString false """
1482+
type C () =
1483+
member __.LongMethodWithLotsOfParameters(aVeryLongType : AVeryLongTypeThatYouNeedToUse, aSecondVeryLongType : AVeryLongTypeThatYouNeedToUse,aThirdVeryLongType : AVeryLongTypeThatYouNeedToUse) =
1484+
someImplementation aVeryLongType aSecondVeryLongType aThirdVeryLongType
1485+
""" { config with
1486+
SpaceBeforeClassConstructor = true
1487+
SpaceBeforeColon = true
1488+
AlternativeLongMemberDefinitions = true }
1489+
|> prepend newline
1490+
|> should equal """
1491+
type C () =
1492+
member __.LongMethodWithLotsOfParameters
1493+
(
1494+
aVeryLongType : AVeryLongTypeThatYouNeedToUse,
1495+
aSecondVeryLongType : AVeryLongTypeThatYouNeedToUse,
1496+
aThirdVeryLongType : AVeryLongTypeThatYouNeedToUse
1497+
)
1498+
=
1499+
someImplementation aVeryLongType aSecondVeryLongType aThirdVeryLongType
1500+
"""
1501+
1502+
[<Test>]
1503+
let ``alternative long member definition with return type`` () =
1504+
formatSourceString false """
1505+
type C () =
1506+
member __.LongMethodWithLotsOfParameters(aVeryLongType : AVeryLongTypeThatYouNeedToUse, aSecondVeryLongType : AVeryLongTypeThatYouNeedToUse,aThirdVeryLongType : AVeryLongTypeThatYouNeedToUse) : int =
1507+
someImplementation aVeryLongType aSecondVeryLongType aThirdVeryLongType
1508+
""" { config with
1509+
SpaceBeforeClassConstructor = true
1510+
SpaceBeforeColon = true
1511+
AlternativeLongMemberDefinitions = true }
1512+
|> prepend newline
1513+
|> should equal """
1514+
type C () =
1515+
member __.LongMethodWithLotsOfParameters
1516+
(
1517+
aVeryLongType : AVeryLongTypeThatYouNeedToUse,
1518+
aSecondVeryLongType : AVeryLongTypeThatYouNeedToUse,
1519+
aThirdVeryLongType : AVeryLongTypeThatYouNeedToUse
1520+
)
1521+
: int
1522+
=
1523+
someImplementation aVeryLongType aSecondVeryLongType aThirdVeryLongType
1524+
"""
1525+
1526+
// See https://github.com/dotnet/docs/issues/18806#issuecomment-655281219
1527+
1528+
[<Test>]
1529+
let ``member, tuple (non-curried), with return type:`` () =
1530+
formatSourceString false """
1531+
type MyClass() =
1532+
member _.LongMethodWithLotsOfParameters(aVeryLongType: AVeryLongTypeThatYouNeedToUse, aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse, aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse) : AVeryLongReturnType =
1533+
someFunction aVeryLongType aSecondVeryLongType aThirdVeryLongType
1534+
""" config
1535+
|> prepend newline
1536+
|> should equal """
1537+
type MyClass() =
1538+
member _.LongMethodWithLotsOfParameters(aVeryLongType: AVeryLongTypeThatYouNeedToUse,
1539+
aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse,
1540+
aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse)
1541+
: AVeryLongReturnType =
1542+
someFunction aVeryLongType aSecondVeryLongType aThirdVeryLongType
1543+
"""
1544+
1545+
[<Test>]
1546+
let ``member, tuple (non-curried), with no return type:`` () =
1547+
formatSourceString false """
1548+
type MyClass() =
1549+
member _.LongMethodWithLotsOfParameters(aVeryLongType: AVeryLongTypeThatYouNeedToUse, aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse, aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse) =
1550+
someFunction aVeryLongType aSecondVeryLongType aThirdVeryLongType
1551+
""" config
1552+
|> prepend newline
1553+
|> should equal """
1554+
type MyClass() =
1555+
member _.LongMethodWithLotsOfParameters(aVeryLongType: AVeryLongTypeThatYouNeedToUse,
1556+
aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse,
1557+
aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse) =
1558+
someFunction aVeryLongType aSecondVeryLongType aThirdVeryLongType
1559+
"""
1560+
1561+
[<Test>]
1562+
let ``member, curried (non-tuple), with return type:`` () =
1563+
formatSourceString false """
1564+
type MyClass() =
1565+
member _.LongMethodWithLotsOfParameters(aVeryLongType: AVeryLongTypeThatYouNeedToUse) (aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse) (aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse) : AVeryLongReturnType =
1566+
someFunction aVeryLongType aSecondVeryLongType aThirdVeryLongType
1567+
""" config
1568+
|> prepend newline
1569+
|> should equal """
1570+
type MyClass() =
1571+
member _.LongMethodWithLotsOfParameters (aVeryLongType: AVeryLongTypeThatYouNeedToUse)
1572+
(aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse)
1573+
(aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse)
1574+
: AVeryLongReturnType =
1575+
someFunction aVeryLongType aSecondVeryLongType aThirdVeryLongType
1576+
"""
1577+
1578+
[<Test>]
1579+
let ``member, curried (non-tuple), with no return type:`` () =
1580+
formatSourceString false """
1581+
type MyClass() =
1582+
member _.LongMethodWithLotsOfParameters(aVeryLongType: AVeryLongTypeThatYouNeedToUse) (aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse) (aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse) =
1583+
someFunction aVeryLongType aSecondVeryLongType aThirdVeryLongType
1584+
""" config
1585+
|> prepend newline
1586+
|> should equal """
1587+
type MyClass() =
1588+
member _.LongMethodWithLotsOfParameters (aVeryLongType: AVeryLongTypeThatYouNeedToUse)
1589+
(aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse)
1590+
(aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse)
1591+
=
1592+
someFunction aVeryLongType aSecondVeryLongType aThirdVeryLongType
1593+
"""
1594+
1595+
[<Test>]
1596+
let ``alternative long class constructor`` () =
1597+
formatSourceString false """
1598+
type C(aVeryLongType: AVeryLongTypeThatYouNeedToUse,
1599+
aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse,
1600+
aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse) =
1601+
class
1602+
end
1603+
""" { config with
1604+
AlternativeLongMemberDefinitions = true
1605+
SpaceBeforeColon = true }
1606+
|> prepend newline
1607+
|> should equal """
1608+
type C
1609+
(
1610+
aVeryLongType : AVeryLongTypeThatYouNeedToUse,
1611+
aSecondVeryLongType : AVeryLongTypeThatYouNeedToUse,
1612+
aThirdVeryLongType : AVeryLongTypeThatYouNeedToUse
1613+
)
1614+
=
1615+
class
1616+
end
1617+
"""
1618+
1619+
[<Test>]
1620+
let ``alternative long class constructor with access modifier`` () =
1621+
formatSourceString false """
1622+
type C internal (aVeryLongType: AVeryLongTypeThatYouNeedToUse,
1623+
aSecondVeryLongType: AVeryLongTypeThatYouNeedToUse,
1624+
aThirdVeryLongType: AVeryLongTypeThatYouNeedToUse) =
1625+
class
1626+
end
1627+
""" { config with
1628+
AlternativeLongMemberDefinitions = true
1629+
SpaceBeforeColon = true }
1630+
|> prepend newline
1631+
|> should equal """
1632+
type C
1633+
internal
1634+
(
1635+
aVeryLongType : AVeryLongTypeThatYouNeedToUse,
1636+
aSecondVeryLongType : AVeryLongTypeThatYouNeedToUse,
1637+
aThirdVeryLongType : AVeryLongTypeThatYouNeedToUse
1638+
)
1639+
=
1640+
class
1641+
end
1642+
"""

0 commit comments

Comments
 (0)