Skip to content

Commit

Permalink
Default config: PageWidth = 120 (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
auduchinok authored and nojaf committed Apr 21, 2019
1 parent 0131828 commit 4da52c9
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 95 deletions.
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/AttributeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ type Funcs =
|> should equal """[<Extension>]
type Funcs =
[<Extension>]
static member ToFunc(f: Action<_, _, _>) =
Func<_, _, _, _>(fun a b c -> f.Invoke(a, b, c))
static member ToFunc(f: Action<_, _, _>) = Func<_, _, _, _>(fun a b c -> f.Invoke(a, b, c))
"""

[<Test>]
Expand Down
10 changes: 3 additions & 7 deletions src/Fantomas.Tests/ClassTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ and File(filename: string, containingFolder: Folder) =
type Folder(pathIn: string) =
let path = pathIn
let filenameArray: string array = System.IO.Directory.GetFiles(path)
member this.FileArray =
Array.map (fun elem -> new File(elem, this)) filenameArray
member this.FileArray = Array.map (fun elem -> new File(elem, this)) filenameArray
and File(filename: string, containingFolder: Folder) =
member __.Name = filename
Expand Down Expand Up @@ -338,8 +337,7 @@ System.String.Concat("a", "b" +
member __.Property = "hello"
let longNamedFunlongNamedFunlongNamedFunlongNamedFunlongNamedFun (x: T) = x
let longNamedClasslongNamedClasslongNamedClasslongNamedClasslongNamedClasslongNamedClass =
T()
let longNamedClasslongNamedClasslongNamedClasslongNamedClasslongNamedClasslongNamedClass = T()
System.String.Concat
("a",
Expand All @@ -358,7 +356,5 @@ type Exception with
|> should equal """open System
type Exception with
member inline __.FirstLine =
(__.Message.Split
([| Environment.NewLine |], StringSplitOptions.RemoveEmptyEntries)).[0]
member inline __.FirstLine = __.Message.Split([| Environment.NewLine |], StringSplitOptions.RemoveEmptyEntries).[0]
"""
6 changes: 2 additions & 4 deletions src/Fantomas.Tests/ComparisonTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ let ``should keep the = on the same line in record def``() =
let doRead (reader: JsonReader) = reader.Read() |> ignore
override x.CanConvert(typ: Type) =
let result =
((typ.GetInterface(typeof<System.Collections.IEnumerable>.FullName) = null)
&& FSharpType.IsUnion typ)
((typ.GetInterface(typeof<System.Collections.IEnumerable>.FullName) = null) && FSharpType.IsUnion typ)
result
"""

Expand All @@ -30,6 +29,5 @@ let ``should keep the = on the same line in record def``() =
let ``should keep the = on the same line``() =
formatSourceString false """trimSpecialChars(controller.ServerName.ToUpper()) = trimSpecialChars(serverFilter.ToUpper())
""" config
|> should equal """trimSpecialChars (controller.ServerName.ToUpper()) = trimSpecialChars
(serverFilter.ToUpper())
|> should equal """trimSpecialChars (controller.ServerName.ToUpper()) = trimSpecialChars (serverFilter.ToUpper())
"""
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ let factors number =
|> Seq.filter (fun x -> number % x = 0L)""" config
|> prepend newline
|> should equal """
let factors number =
{ 2L..number / 2L } |> Seq.filter (fun x -> number % x = 0L)
let factors number = { 2L..number / 2L } |> Seq.filter (fun x -> number % x = 0L)
"""

[<Test>]
Expand Down
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/ControlStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ let test x y =
else if x > y then "is greater than"
else "Don't know"
if age < 10 then
printfn "You are only %d years old and already learning F#? Wow!" age
if age < 10 then printfn "You are only %d years old and already learning F#? Wow!" age
"""

[<Test>]
Expand Down
4 changes: 1 addition & 3 deletions src/Fantomas.Tests/DataStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ let vectorLength vec =
| [| var1 |] -> var1
| [| var1; var2 |] -> sqrt (var1 * var1 + var2 * var2)
| [| var1; var2; var3 |] -> sqrt (var1 * var1 + var2 * var2 + var3 * var3)
| _ ->
failwith "vectorLength called with an unsupported array size of %d."
(vec.Length)
| _ -> failwith "vectorLength called with an unsupported array size of %d." (vec.Length)
"""

[<Test>]
Expand Down
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/FormattingSelectionOnlyTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ let rangeTest testValue mid size =
let (var1, var2) as tuple1 = (1, 2)""" config
|> append newline
|> should equal """match testValue with
| var1 when var1 >= mid - size / 2 && var1 <= mid + size / 2 ->
printfn "The test value is in range."
| var1 when var1 >= mid - size / 2 && var1 <= mid + size / 2 -> printfn "The test value is in range."
| _ -> printfn "The test value is out of range."
"""

Expand Down
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/FormattingSelectionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ let (var1, var2) as tuple1 = (1, 2)""" config
|> should equal """
let rangeTest testValue mid size =
match testValue with
| var1 when var1 >= mid - size / 2 && var1 <= mid + size / 2 ->
printfn "The test value is in range."
| var1 when var1 >= mid - size / 2 && var1 <= mid + size / 2 -> printfn "The test value is in range."
| _ -> printfn "The test value is out of range."
let (var1, var2) as tuple1 = (1, 2)"""
Expand Down
6 changes: 2 additions & 4 deletions src/Fantomas.Tests/FunctionDefinitionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ let inline heterogenousAdd(value1 : ^T when (^T or ^U) : (static member (+) : ^T
value1 + value2""" config
|> prepend newline
|> should equal """
let inline add (value1: ^T when ^T: (static member (+): ^T * ^T -> ^T),
value2: ^T) = value1 + value2
let inline heterogenousAdd (value1: ^T when (^T or ^U): (static member (+): ^T * ^U
-> ^T), value2: ^U) =
let inline add (value1: ^T when ^T: (static member (+): ^T * ^T -> ^T), value2: ^T) = value1 + value2
let inline heterogenousAdd (value1: ^T when (^T or ^U): (static member (+): ^T * ^U -> ^T), value2: ^U) =
value1 + value2
"""

Expand Down
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/NoTrailingSpacesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ let ``should not confuse me with an extra space at end of line v2``() =
formatSourceString false codeSnippet config
|> should equal """let ``should not extrude without positive distance``() =
let args = [| "-i"; "input.dxf"; "-o"; "output.pdf"; "--op"; "extrude" |]
(fun () -> parseCmdLine args |> ignore)
|> should throw typeof<Argu.ArguParseException>
(fun () -> parseCmdLine args |> ignore) |> should throw typeof<Argu.ArguParseException>
"""
4 changes: 2 additions & 2 deletions src/Fantomas.Tests/OperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ let ``should pattern match on quotation expression``() =
let ``should break on . operator``() =
formatSourceString false """pattern.Replace(".", @"\.").Replace("$", @"\$").Replace("^", @"\^").Replace("{", @"\{").Replace("[", @"\[").Replace("(", @"\(").Replace(")", @"\)").Replace("+", @"\+")
""" config
""" { config with PageWidth = 80 }
|> prepend newline
|> should equal """
pattern.Replace(".", @"\.").Replace("$", @"\$").Replace("^", @"\^")
Expand All @@ -106,7 +106,7 @@ let ``should break on . operator and keep indentation``() =
(x + y)
.Replace(seperator + "**" + seperator, replacementSeparator + "(.|?" + replacementSeparator + ")?" )
.Replace("**" + seperator, ".|(?<=^|" + replacementSeparator + ")" )
""" config
""" { config with PageWidth = 80 }
|> should equal """let pattern =
(x + y)
.Replace(seperator + "**" + seperator,
Expand Down
11 changes: 4 additions & 7 deletions src/Fantomas.Tests/PatternMatchingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ printfn "%d %d %A" var1 var2 tuple1""" config
|> should equal """
let rangeTest testValue mid size =
match testValue with
| var1 when var1 >= mid - size / 2 && var1 <= mid + size / 2 ->
printfn "The test value is in range."
| var1 when var1 >= mid - size / 2 && var1 <= mid + size / 2 -> printfn "The test value is in range."
| _ -> printfn "The test value is out of range."
let (var1, var2) as tuple1 = (1, 2)
Expand Down Expand Up @@ -197,7 +196,7 @@ try
fst(find (fun (s, (s', ty): int * int) ->
s' = s0 && can (type_match ty ty0) []) (!the_interface))
with
| Failure _ -> s0""" config
| Failure _ -> s0""" { config with PageWidth = 80 }
|> prepend newline
|> should equal """
try
Expand All @@ -215,8 +214,7 @@ find (fun (Ident op) x y -> Combp(Combp(Varp(op,dpty),x),y)) "term after binary
""" config
|> prepend newline
|> should equal """
find (fun (Ident op) x y -> Combp(Combp(Varp(op, dpty), x), y))
"term after binary operator" inp
find (fun (Ident op) x y -> Combp(Combp(Varp(op, dpty), x), y)) "term after binary operator" inp
"""

[<Test>]
Expand Down Expand Up @@ -380,8 +378,7 @@ let (|OneLinerBinding|MultilineBinding|) b =
| DoBinding([], PreXmlDoc [||], OneLinerExpr _)
| MemberBinding([], PreXmlDoc [||], _, _, _, _, OneLinerExpr _)
| PropertyBinding([], PreXmlDoc [||], _, _, _, _, OneLinerExpr _)
| ExplicitCtor([], PreXmlDoc [||], _, _, OneLinerExpr _, _) ->
OneLinerBinding b
| ExplicitCtor([], PreXmlDoc [||], _, _, OneLinerExpr _, _) -> OneLinerBinding b
| _ -> MultilineBinding b
"""

Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/PipingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let f x =
<|> if someveryveryveryverylongexpression then someveryveryveryverylongexpression else someveryveryveryverylongexpression
<|> if someveryveryveryverylongexpression then someveryveryveryverylongexpression else someveryveryveryverylongexpression
|> f
""" config
""" { config with PageWidth = 80 }
|> prepend newline
|> should equal """
let f x =
Expand Down
11 changes: 3 additions & 8 deletions src/Fantomas.Tests/QuotationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ let ``untyped quotations``() =

[<Test>]
let ``should preserve unit literal``() =
formatSourceString false """
let logger = Mock<ILogger>().Setup(fun log -> <@ log.Log(error) @>).Returns(()).Create()
""" config
|> prepend newline
|> should equal """
let logger =
Mock<ILogger>().Setup(fun log -> <@ log.Log(error) @>).Returns(()).Create()
"""
shouldNotChangeAfterFormat """
let logger = Mock<ILogger>().Setup(fun log -> <@ log.Log(error) @>).Returns(()).Create()
"""
15 changes: 2 additions & 13 deletions src/Fantomas.Tests/RecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ type Element =
/// Replaces the children.
static member (-): self:Element * children:#seq<#INode> -> Element
/// Replaces the attributes.
static member WithAttributes: attrs:#seq<string * string>
-> self:Element -> Element
static member WithAttributes: attrs:#seq<string * string> -> self:Element -> Element
/// Replaces the attributes.
static member (+): self:Element * attrs:#seq<string * string> -> Element
/// Replaces the children with a single text node.
Expand Down Expand Up @@ -194,22 +193,12 @@ type rate2 = Rate of float<GBP / SGD * USD>

[<Test>]
let ``should keep comments on records``() =
formatSourceString false """
shouldNotChangeAfterFormat """
let newDocument = //somecomment
{ program = Encoding.Default.GetBytes(document.Program) |> Encoding.UTF8.GetString
content = Encoding.Default.GetBytes(document.Content) |> Encoding.UTF8.GetString
created = document.Created.ToLocalTime() }
|> JsonConvert.SerializeObject
""" config
|> prepend newline
|> should equal """
let newDocument = //somecomment
{ program =
Encoding.Default.GetBytes(document.Program) |> Encoding.UTF8.GetString
content =
Encoding.Default.GetBytes(document.Content) |> Encoding.UTF8.GetString
created = document.Created.ToLocalTime() }
|> JsonConvert.SerializeObject
"""

[<Test>]
Expand Down
19 changes: 7 additions & 12 deletions src/Fantomas.Tests/SignatureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,20 @@ let ``should keep the (string * string) list type signature in records``() =

[<Test>]
let ``should keep the (string * string) list type signature in functions``() =
formatSourceString false """let MSBuildWithProjectProperties outputPath (targets : string)
(properties : string -> (string * string) list) projects = doingsomstuff
""" config
|> should equal """let MSBuildWithProjectProperties outputPath (targets: string)
(properties: string -> (string * string) list) projects = doingsomstuff
shouldNotChangeAfterFormat """
let MSBuildWithProjectProperties outputPath (targets: string) (properties: string -> (string * string) list) projects =
doingsomstuff
"""


[<Test>]
let ``should keep the string * string list type signature in functions``() =
formatSourceString false """let MSBuildWithProjectProperties outputPath (targets : string)
(properties : (string -> string) * string list) projects = doingsomstuff
""" config
|> should equal """let MSBuildWithProjectProperties outputPath (targets: string)
(properties: (string -> string) * string list) projects = doingsomstuff
shouldNotChangeAfterFormat """
let MSBuildWithProjectProperties outputPath (targets: string) (properties: (string -> string) * string list) projects =
doingsomstuff
"""


[<Test>]
let ``should not add parens in signature``() =
formatSourceString false """type Route =
Expand Down
13 changes: 4 additions & 9 deletions src/Fantomas.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,7 @@ let ``should keep the ? in optional parameters``() =
""" config
|> should equal """type Shell() =
static member private GetParams(cmd, ?args) = doStuff
static member Exec(cmd, ?args) =
shellExec (Shell.GetParams(cmd, ?args = args))
static member Exec(cmd, ?args) = shellExec (Shell.GetParams(cmd, ?args = args))
"""

[<Test>]
Expand Down Expand Up @@ -612,14 +611,10 @@ type BlobHelper(Account: CloudStorageAccount) =
new(configurationSettingName, hostedService) =
CloudStorageAccount.SetConfigurationSettingPublisher(fun configName configSettingPublisher ->
let connectionString =
if hostedService then
RoleEnvironment.GetConfigurationSettingValue(configName)
else
ConfigurationManager.ConnectionStrings.[configName].ConnectionString
if hostedService then RoleEnvironment.GetConfigurationSettingValue(configName)
else ConfigurationManager.ConnectionStrings.[configName].ConnectionString
configSettingPublisher.Invoke(connectionString) |> ignore)
BlobHelper
(CloudStorageAccount.FromConfigurationSetting
(configurationSettingName))
BlobHelper(CloudStorageAccount.FromConfigurationSetting(configurationSettingName))
"""

[<Test>]
Expand Down
15 changes: 3 additions & 12 deletions src/Fantomas.Tests/UnionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,13 @@ type X =

[<Test>]
let ``enums conversion``() =
formatSourceString false """
type uColor =
| Red = 0u
| Green = 1u
| Blue = 2u
let col3 = Microsoft.FSharp.Core.LanguagePrimitives.EnumOfValue<uint32, uColor>(2u)""" config
|> prepend newline
|> should equal """
shouldNotChangeAfterFormat """
type uColor =
| Red = 0u
| Green = 1u
| Blue = 2u
let col3 =
Microsoft.FSharp.Core.LanguagePrimitives.EnumOfValue<uint32, uColor>(2u)
let col3 = Microsoft.FSharp.Core.LanguagePrimitives.EnumOfValue<uint32, uColor>(2u)
"""

[<Test>]
Expand Down Expand Up @@ -149,8 +141,7 @@ type uColor =
| Green = 1u
| Blue = 2u
let col3 =
Microsoft.FSharp.Core.LanguagePrimitives.EnumOfValue<uint32, uColor>(2u)
let col3 = Microsoft.FSharp.Core.LanguagePrimitives.EnumOfValue<uint32, uColor>(2u)
"""

[<Test>]
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas/FormatConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type FormatConfig =

static member Default =
{ IndentSpaceNum = 4
PageWidth = 80
PageWidth = 120
PreserveEndOfLine = false
SemicolonAtEndOfLine = false
SpaceBeforeArgument = true
Expand Down

0 comments on commit 4da52c9

Please sign in to comment.