diff --git a/src/Fantomas.Tests/ActivePatternTests.fs b/src/Fantomas.Tests/ActivePatternTests.fs index cb671e809b..a35497d1fb 100644 --- a/src/Fantomas.Tests/ActivePatternTests.fs +++ b/src/Fantomas.Tests/ActivePatternTests.fs @@ -59,7 +59,7 @@ let (|Integer|_|) (str : string) = let (|ParseRegex|_|) regex str = let m = Regex(regex).Match(str) - if m.Success then + if m.Success then Some(List.tail [ for x in m.Groups -> x.Value ]) else None """ diff --git a/src/Fantomas.Tests/ClassTests.fs b/src/Fantomas.Tests/ClassTests.fs index 3249f774da..f7cc369f42 100644 --- a/src/Fantomas.Tests/ClassTests.fs +++ b/src/Fantomas.Tests/ClassTests.fs @@ -100,23 +100,23 @@ type Shape2D(x0 : float, y0 : float) = type Shape2D(x0 : float, y0 : float) = let mutable x, y = x0, y0 let mutable rotAngle = 0.0 - + member this.CenterX with get () = x and set xval = x <- xval - + member this.CenterY with get () = y and set yval = y <- yval - + abstract Area : float abstract Perimeter : float abstract Name : string - + member this.Move dx dy = x <- x + dx y <- y + dy - + abstract Rotate : float -> unit override this.Rotate(angle) = rotAngle <- rotAngle + angle """ @@ -221,13 +221,13 @@ type MyClassDerived2(y: int) = |> should equal """ type MyClassBase2(x : int) = let mutable z = x * x - do + do for i in 1..z do printf "%d " i type MyClassDerived2(y : int) = inherit MyClassBase2(y * 2) - do + do for i in 1..y do printf "%d " i """ @@ -291,7 +291,7 @@ let ``member properties with type annotation``() = """ config |> should equal """type A() = member this.X : int = 1 - + member this.Y with get () : int = 1 and set (_ : int) : unit = () @@ -343,8 +343,8 @@ let longNamedClasslongNamedClasslongNamedClasslongNamedClasslongNamedClasslongNa T() System.String.Concat - ("a", - "b" + ("a", + "b" + (longNamedFunlongNamedFunlongNamedFunlongNamedFunlongNamedFun (longNamedClasslongNamedClasslongNamedClasslongNamedClasslongNamedClasslongNamedClass)).Property) """ diff --git a/src/Fantomas.Tests/CommentTests.fs b/src/Fantomas.Tests/CommentTests.fs index 37e692993c..a60c3cbdba 100644 --- a/src/Fantomas.Tests/CommentTests.fs +++ b/src/Fantomas.Tests/CommentTests.fs @@ -41,7 +41,7 @@ let print_30_permut() = let print_30_permut() = /// declare and initialize let permutation : int array = - Array.init n (fun i -> + Array.init n (fun i -> Console.Write(i + 1) i) permutation @@ -61,7 +61,7 @@ let print_30_permut() = let print_30_permut() = /// declare and initialize let permutation : int array = - Array.init n (fun (i, j) -> + Array.init n (fun (i, j) -> Console.Write(i + 1) i) permutation @@ -207,8 +207,8 @@ type IlxGenIntraAssemblyInfo = |> should equal """ /// Non-local information related to internals of code generation within an assembly type IlxGenIntraAssemblyInfo = - { /// A table recording the generated name of the static backing fields for each mutable top level value where - /// we may need to take the address of that value, e.g. static mutable module-bound values which are structs. These are + { /// A table recording the generated name of the static backing fields for each mutable top level value where + /// we may need to take the address of that value, e.g. static mutable module-bound values which are structs. These are /// only accessible intra-assembly. Across assemblies, taking the address of static mutable module-bound values is not permitted. /// The key to the table is the method ref for the property getter for the value, which is a stable name for the Val's /// that come from both the signature and the implementation. @@ -279,7 +279,7 @@ type IlxGenOptions = generateFilterBlocks : bool; workAroundReflectionEmitBugs : bool; emitConstantArraysUsingStaticDataBlobs : bool; - // If this is set, then the last module becomes the "main" module and its toplevel bindings are executed at startup + // If this is set, then the last module becomes the "main" module and its toplevel bindings are executed at startup mainMethodInfo : Tast.Attribs option; localOptimizationsAreOn : bool; generateDebugSymbols : bool; diff --git a/src/Fantomas.Tests/ComparisonTests.fs b/src/Fantomas.Tests/ComparisonTests.fs index 46d87bb3cd..4faa39d59a 100644 --- a/src/Fantomas.Tests/ComparisonTests.fs +++ b/src/Fantomas.Tests/ComparisonTests.fs @@ -25,7 +25,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.FullName) = null) + ((typ.GetInterface(typeof.FullName) = null) && FSharpType.IsUnion typ) result """ @@ -35,6 +35,6 @@ 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 + |> should equal """trimSpecialChars (controller.ServerName.ToUpper()) = trimSpecialChars (serverFilter.ToUpper()) """ diff --git a/src/Fantomas.Tests/CompilerDirectivesTests.fs b/src/Fantomas.Tests/CompilerDirectivesTests.fs index b918b0089f..79c3141cbf 100644 --- a/src/Fantomas.Tests/CompilerDirectivesTests.fs +++ b/src/Fantomas.Tests/CompilerDirectivesTests.fs @@ -213,7 +213,7 @@ namespace Internal.Utilities.Diagnostic #if EXTENSIBLE_DUMPER #if DEBUG type ExtensibleDumper = A | B -#endif +#endif #endif diff --git a/src/Fantomas.Tests/ComputationExpressionTests.fs b/src/Fantomas.Tests/ComputationExpressionTests.fs index 64169922b0..9248072ff2 100644 --- a/src/Fantomas.Tests/ComputationExpressionTests.fs +++ b/src/Fantomas.Tests/ComputationExpressionTests.fs @@ -24,8 +24,8 @@ let fetchAsync(name, url:string) = |> prepend newline |> should equal """ let fetchAsync (name, url : string) = - async { - try + async { + try let uri = new System.Uri(url) let webClient = new WebClient() let! html = webClient.AsyncDownloadString(uri) @@ -46,7 +46,7 @@ let comp = |> prepend newline |> should equal """ let comp = - eventually { + eventually { for x in 1..2 do printfn " x = %d" x return 3 + 4 @@ -71,16 +71,16 @@ let rec inorder tree = |> prepend newline |> should equal """ let s1 = - seq { + seq { for i in 1..10 -> i * i } let s2 = seq { 0..10..100 } let rec inorder tree = - seq { + seq { match tree with - | Tree(x, left, right) -> + | Tree(x, left, right) -> yield! inorder left yield x yield! inorder right @@ -110,7 +110,7 @@ async { }""" config |> prepend newline |> should equal """ -async { +async { match! myAsyncFunction() with | Some x -> printfn "%A" x | None -> printfn "Function returned None!" diff --git a/src/Fantomas.Tests/ControlStructureTests.fs b/src/Fantomas.Tests/ControlStructureTests.fs index db84273b50..0babc2a2b4 100644 --- a/src/Fantomas.Tests/ControlStructureTests.fs +++ b/src/Fantomas.Tests/ControlStructureTests.fs @@ -28,7 +28,7 @@ then printfn "You are only %d years old and already learning F#? Wow!" age""" co |> should equal """ let rec tryFindMatch pred list = match list with - | head :: tail -> + | head :: tail -> if pred (head) then Some(head) else tryFindMatch pred tail | [] -> None @@ -39,7 +39,7 @@ let test x y = else if x > y then "is greater than" else "Don't know" -if age < 10 then +if age < 10 then printfn "You are only %d years old and already learning F#? Wow!" age """ @@ -92,7 +92,7 @@ let lookForValue value maxValue = while continueLooping do let rand = randomNumberGenerator.Next(maxValue) printf "%d " rand - if rand = value then + if rand = value then printfn "\nFound a %d!" value continueLooping <- false @@ -113,9 +113,9 @@ let result1 = divide1 100 0 |> prepend newline |> should equal """ let divide1 x y = - try + try Some(x / y) - with :? System.DivideByZeroException -> + with :? System.DivideByZeroException -> printfn "Division by zero!" None @@ -139,8 +139,8 @@ let ``try/with and finally``() = |> prepend newline |> should equal """ let function1 x y = - try - try + try + try if x = y then raise (InnerError("inner")) else raise (OuterError("outer")) with @@ -223,7 +223,7 @@ let x = |> prepend newline |> should equal """ let x = - if try + if try true with Failure _ -> false then () @@ -255,7 +255,7 @@ let handle = |> prepend newline |> should equal """ let handle = - if n < weakThreshhold then + if n < weakThreshhold then assert onStrongDiscard.IsNone // it disappeared Weak(WeakReference(v)) else Strong(v) diff --git a/src/Fantomas.Tests/DataStructureTests.fs b/src/Fantomas.Tests/DataStructureTests.fs index 0137637e51..b2a7f96f6e 100644 --- a/src/Fantomas.Tests/DataStructureTests.fs +++ b/src/Fantomas.Tests/DataStructureTests.fs @@ -64,7 +64,7 @@ let listLength list = |> should equal """ let rec printList l = match l with - | head :: tail -> + | head :: tail -> printf "%d " head printList tail | [] -> printfn "" @@ -94,8 +94,8 @@ 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." + | _ -> + failwith "vectorLength called with an unsupported array size of %d." (vec.Length) """ @@ -109,7 +109,7 @@ let ``should keep -> notation``() = |> prepend newline |> should equal """ let environVars target = - [ for e in Environment.GetEnvironmentVariables target -> + [ for e in Environment.GetEnvironmentVariables target -> let e1 = e :?> Collections.DictionaryEntry e1.Key, e1.Value ] """ diff --git a/src/Fantomas.Tests/Fantomas.Tests.fsproj b/src/Fantomas.Tests/Fantomas.Tests.fsproj index 63aeadd896..65812180f9 100644 --- a/src/Fantomas.Tests/Fantomas.Tests.fsproj +++ b/src/Fantomas.Tests/Fantomas.Tests.fsproj @@ -40,6 +40,7 @@ + diff --git a/src/Fantomas.Tests/FormattingSelectionOnlyTests.fs b/src/Fantomas.Tests/FormattingSelectionOnlyTests.fs index 84d5bfb0d8..33ff913ea2 100644 --- a/src/Fantomas.Tests/FormattingSelectionOnlyTests.fs +++ b/src/Fantomas.Tests/FormattingSelectionOnlyTests.fs @@ -32,7 +32,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 -> + | 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." """ diff --git a/src/Fantomas.Tests/FormattingSelectionTests.fs b/src/Fantomas.Tests/FormattingSelectionTests.fs index f3ce01511a..ac6c3fd4d7 100644 --- a/src/Fantomas.Tests/FormattingSelectionTests.fs +++ b/src/Fantomas.Tests/FormattingSelectionTests.fs @@ -38,7 +38,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 -> + | 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." @@ -246,7 +246,7 @@ let comp = return 3 + 4 }""" config |> should equal """ let comp = - eventually { + eventually { for x in 1..2 do printfn " x = %d" x return 3 + 4 diff --git a/src/Fantomas.Tests/FunctionDefinitionTests.fs b/src/Fantomas.Tests/FunctionDefinitionTests.fs index e78d3417e9..a6f883ce6a 100644 --- a/src/Fantomas.Tests/FunctionDefinitionTests.fs +++ b/src/Fantomas.Tests/FunctionDefinitionTests.fs @@ -29,10 +29,10 @@ type C () = |> prepend newline |> should equal """ type C() = - + let rec g x = h x and h x = g x - + member x.P = g 3 """ @@ -101,7 +101,7 @@ let ``let bindings with return types``() = let divide x y = let stream : System.IO.FileStream = System.IO.File.Create("test.txt") let writer : System.IO.StreamWriter = new System.IO.StreamWriter(stream) - try + try writer.WriteLine("test1") Some(x / y) finally @@ -129,10 +129,10 @@ 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), +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), + -> ^T), value2 : ^U) = value1 + value2 """ @@ -163,11 +163,11 @@ let ``should add spaces between multiline nested let bindings``() = let f2 x = let _ = () x + 1 - + let f3 y = let _ = () y + 1 - + x + y """ @@ -178,7 +178,7 @@ let ``should indent fun blocks``() = let y = 1 x""" config |> should equal """let f = - fun x -> + fun x -> let y = 1 x """ @@ -255,7 +255,7 @@ open System.Runtime.InteropServices open Accessibility [] -extern int AccessibleChildren(IAccessible paccContainer, int iChildStart, int cChildren, [] System.Object [] rgvarChildren, int* pcObtained) """ @@ -270,7 +270,7 @@ let f = fun x -> match x with X (x) -> x type U = X of int let f = - fun x -> + fun x -> match x with | X(x) -> x """ diff --git a/src/Fantomas.Tests/InterfaceTests.fs b/src/Fantomas.Tests/InterfaceTests.fs index 907c43e32f..ae064fd54a 100644 --- a/src/Fantomas.Tests/InterfaceTests.fs +++ b/src/Fantomas.Tests/InterfaceTests.fs @@ -163,11 +163,11 @@ type LogInterface = type MyLogInteface() = interface LogInterface with member x.Print msg = printfn "%s" msg - + override x.GetLogFile environment = if environment = "DEV" then "dev.log" else sprintf "date-%s.log" environment - + member x.Info() = () override x.Version() = () """ diff --git a/src/Fantomas.Tests/ModuleTests.fs b/src/Fantomas.Tests/ModuleTests.fs index 902a705765..2658ca36fc 100644 --- a/src/Fantomas.Tests/ModuleTests.fs +++ b/src/Fantomas.Tests/ModuleTests.fs @@ -90,7 +90,7 @@ module Y = |> should equal """ module Y = let x = 1 - + module Z = let z = 5 """ @@ -211,7 +211,7 @@ namespace Test module rec Expression = type Add = Expr * Expr - + type Expr = | Add of Add | Value of int diff --git a/src/Fantomas.Tests/NoTrailingSpacesTests.fs b/src/Fantomas.Tests/NoTrailingSpacesTests.fs new file mode 100644 index 0000000000..073a8755c8 --- /dev/null +++ b/src/Fantomas.Tests/NoTrailingSpacesTests.fs @@ -0,0 +1,20 @@ +module Fantomas.Tests.NoTrailingSpacesTests + +open NUnit.Framework +open FsUnit + +open Fantomas.Tests.TestHelper + +[] +let ``should not confuse me with an extra space at end of line v2``() = + let codeSnippet = """let ``should not extrude without positive distance`` () = + let args = [| "-i"; "input.dxf"; "-o"; "output.pdf"; "--op"; "extrude"; |] + (fun () -> parseCmdLine args |> ignore) + |> should throw typeof""" + + 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 +""" \ No newline at end of file diff --git a/src/Fantomas.Tests/OperatorTests.fs b/src/Fantomas.Tests/OperatorTests.fs index 83f7d872cf..a70fe2e1d8 100644 --- a/src/Fantomas.Tests/OperatorTests.fs +++ b/src/Fantomas.Tests/OperatorTests.fs @@ -82,7 +82,7 @@ let ``should pattern match on quotation expression``() = | _ -> ()""" config |> should equal """let rec print expr = match expr with - | SpecificCall <@@ (+) @@> (_, _, exprList) -> + | SpecificCall <@@ (+) @@> (_, _, exprList) -> print exprList.Head printf " + " print exprList.Tail.Head @@ -111,7 +111,7 @@ let ``should break on . operator and keep indentation``() = """ config |> should equal """let pattern = (x + y) - .Replace(seperator + "**" + seperator, + .Replace(seperator + "**" + seperator, replacementSeparator + "(.|?" + replacementSeparator + ")?") .Replace("**" + seperator, ".|(?<=^|" + replacementSeparator + ")") """ @@ -143,7 +143,7 @@ let ``should understand ? as an infix operator``() = |> (fun x -> x?Invoke (true)) |> fun (t : Task) -> t.Wait() with _ -> ()""" config - |> should equal """try + |> should equal """try item.MethodInfo.Method.Invoke(null, ipa) |> (fun x -> x?Invoke (true)) |> fun (t : Task) -> t.Wait() diff --git a/src/Fantomas.Tests/PatternMatchingTests.fs b/src/Fantomas.Tests/PatternMatchingTests.fs index 691b230fd8..8d8c0fed57 100644 --- a/src/Fantomas.Tests/PatternMatchingTests.fs +++ b/src/Fantomas.Tests/PatternMatchingTests.fs @@ -30,7 +30,7 @@ let ``function keyword``() = |> prepend newline |> should equal """ let filterNumbers = - function + function | 1 | 2 | 3 -> printfn "Found 1, 2, or 3!" | a -> printfn "%d" a """ @@ -49,7 +49,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 -> + | 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." @@ -157,10 +157,10 @@ let RegisterControl(control : Control) = let ReadFromFile(reader : System.IO.StreamReader) = match reader.ReadLine() with - | null -> + | null -> printfn "\n" false - | line -> + | line -> printfn "%s" line true """ @@ -196,10 +196,10 @@ with | Failure _ -> s0""" config |> prepend newline |> should equal """ -try - fst - (find - (fun (s, (s', ty) : int * int) -> +try + fst + (find + (fun (s, (s', ty) : int * int) -> s' = s0 && can (type_match ty ty0) []) (!the_interface)) with Failure _ -> s0 """ @@ -211,7 +211,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)) +find (fun (Ident op) x y -> Combp(Combp(Varp(op, dpty), x), y)) "term after binary operator" inp """ @@ -227,7 +227,7 @@ let UNIFY_ACCEPT_TAC mvs th (asl, w) = |> should equal """ let UNIFY_ACCEPT_TAC mvs th (asl, w) = let insts = term_unify mvs (concl th) w - ([], insts), [], + ([], insts), [], let th' = INSTANTIATE insts th fun i [] -> INSTANTIATE i th' """ @@ -281,7 +281,7 @@ let v = |> prepend newline |> should equal """ let v = - List.tryPick (function + List.tryPick (function | 1 -> Some 1 | _ -> None) [ 1; 2; 3 ] """ diff --git a/src/Fantomas.Tests/PipingTests.fs b/src/Fantomas.Tests/PipingTests.fs index 8835e8125b..22095b8e3c 100644 --- a/src/Fantomas.Tests/PipingTests.fs +++ b/src/Fantomas.Tests/PipingTests.fs @@ -19,11 +19,11 @@ let f x = |> prepend newline |> should equal """ let f x = - someveryveryveryverylongexpression - <|> if someveryveryveryverylongexpression then + someveryveryveryverylongexpression + <|> if someveryveryveryverylongexpression then someveryveryveryverylongexpression - else someveryveryveryverylongexpression - <|> if someveryveryveryverylongexpression then + else someveryveryveryverylongexpression + <|> if someveryveryveryverylongexpression then someveryveryveryverylongexpression else someveryveryveryverylongexpression |> f @@ -74,7 +74,7 @@ let prefetchImages = |> should equal """ let prefetchImages = [ playerOImage; playerXImage ] - |> List.map (fun img -> + |> List.map (fun img -> link [ Rel "prefetch" Href img ]) """ diff --git a/src/Fantomas.Tests/PreserveEOLTests.fs b/src/Fantomas.Tests/PreserveEOLTests.fs index aa4f78a712..ecfe940cb2 100644 --- a/src/Fantomas.Tests/PreserveEOLTests.fs +++ b/src/Fantomas.Tests/PreserveEOLTests.fs @@ -434,7 +434,7 @@ let ``remove single pipe without pEOL``() = """ { config with PreserveEndOfLine = false } |> prepend newline |> should equal """ -try +try () with :? _ -> () diff --git a/src/Fantomas.Tests/RecordTests.fs b/src/Fantomas.Tests/RecordTests.fs index ae58e8822d..6f715934d4 100644 --- a/src/Fantomas.Tests/RecordTests.fs +++ b/src/Fantomas.Tests/RecordTests.fs @@ -173,7 +173,7 @@ let rec make item depth = |> prepend newline |> should equal """ let rec make item depth = - if depth > 0 then + if depth > 0 then Tree({ Left = make (2 * item - 1) (depth - 1) Right = make (2 * item) (depth - 1) }, item) else Tree(defaultof<_>, item) diff --git a/src/Fantomas.Tests/SignatureTests.fs b/src/Fantomas.Tests/SignatureTests.fs index e7139de50a..96e9a6eb99 100644 --- a/src/Fantomas.Tests/SignatureTests.fs +++ b/src/Fantomas.Tests/SignatureTests.fs @@ -33,7 +33,7 @@ let ``should keep the (string * string) list type signature in functions``() = (properties : string -> (string * string) list) projects = doingsomstuff """ config - |> should equal """let MSBuildWithProjectProperties outputPath (targets : string) + |> should equal """let MSBuildWithProjectProperties outputPath (targets : string) (properties : string -> (string * string) list) projects = doingsomstuff """ @@ -44,7 +44,7 @@ let ``should keep the string * string list type signature in functions``() = (properties : (string -> string) * string list) projects = doingsomstuff """ config - |> should equal """let MSBuildWithProjectProperties outputPath (targets : string) + |> should equal """let MSBuildWithProjectProperties outputPath (targets : string) (properties : (string -> string) * string list) projects = doingsomstuff """ diff --git a/src/Fantomas.Tests/TypeDeclarationTests.fs b/src/Fantomas.Tests/TypeDeclarationTests.fs index 068b0fd78d..8f1c330afa 100644 --- a/src/Fantomas.Tests/TypeDeclarationTests.fs +++ b/src/Fantomas.Tests/TypeDeclarationTests.fs @@ -70,15 +70,15 @@ type Connection(?rate0 : int, ?duplex0 : DuplexType, ?parity0 : bool) = type Connection(?rate0 : int, ?duplex0 : DuplexType, ?parity0 : bool) = let duplex = defaultArg duplex0 Full let parity = defaultArg parity0 false - + let mutable rate = match rate0 with | Some rate1 -> rate1 - | None -> + | None -> match duplex with | Full -> 9600 | Half -> 4800 - + do printfn "Baud Rate: %d Duplex: %A Parity: %b" rate duplex parity """ @@ -137,20 +137,20 @@ type public MyClass<'a> public (x, y) as this = static let PI = 3.14 static do printfn "static constructor" let mutable z = x + y - - do + + do printfn "%s" (this.ToString()) printfn "more constructor effects" - + internal new(a) = MyClass(a, a) static member StaticProp = PI static member StaticMethod a = a + 1 member internal self.Prop1 = x - + member self.Prop2 with get () = z and set (a) = z <- a - + member self.Method(a, b) = x + y + z + a + b """ @@ -226,7 +226,7 @@ type System.Int32 with System.Int32.Parse(s)""" config |> prepend newline |> should equal """ -/// Define a new member method FromString on the type Int32. +/// Define a new member method FromString on the type Int32. type System.Int32 with member this.FromString(s : string) = System.Int32.Parse(s) """ @@ -256,7 +256,7 @@ type Derived1() = type Derived1() = inherit AbstractBase() let mutable value = 10 - + override this.Property1 with get () = value and set (v : int) = value <- v @@ -278,16 +278,16 @@ type Foo() = member x.Get = 1 member x.Set with private set (v : int) = value <- v - + member x.GetSet with internal get () = value and private set (v : bool) = value <- v - + member x.GetI with internal get (key1, key2) = false member x.SetI with private set (key1, key2) value = () - + member x.GetSetI with internal get (key1, key2) = true and private set (key1, key2) value = () @@ -360,15 +360,15 @@ type NumberStrings() = type NumberStrings() = let mutable ordinals = [| "one" |] let mutable cardinals = [| "first" |] - + member this.Item with get index = ordinals.[index] and set index value = ordinals.[index] <- value - + member this.Ordinal with get (index) = ordinals.[index] and set index value = ordinals.[index] <- value - + member this.Cardinal with get (index) = cardinals.[index] and set index value = cardinals.[index] <- value @@ -394,7 +394,7 @@ open System.Collections.Generic type SparseMatrix() = let mutable table = new Dictionary() - + member this.Item with get (key1, key2) = table.[(key1, key2)] and set (key1, key2) value = table.[(key1, key2)] <- value @@ -499,15 +499,15 @@ type Person(nameIn : string, idIn : int) = let mutable name = nameIn let mutable id = idIn do printfn "Created a person object." - + member this.Name with get () = name and set (v) = name <- v - + member this.ID with get () = id and set (v) = id <- v - + new() = Person("Invalid Name", -1) then printfn "Created an invalid person object." @@ -612,11 +612,11 @@ type BlobHelper(Account : CloudStorageAccount) = |> should equal """ type BlobHelper(Account : CloudStorageAccount) = new(configurationSettingName, hostedService) = - CloudStorageAccount.SetConfigurationSettingPublisher(fun configName configSettingPublisher -> + CloudStorageAccount.SetConfigurationSettingPublisher(fun configName configSettingPublisher -> let connectionString = - if hostedService then + if hostedService then RoleEnvironment.GetConfigurationSettingValue(configName) - else + else ConfigurationManager.ConnectionStrings.[configName].ConnectionString configSettingPublisher.Invoke(connectionString) |> ignore) BlobHelper @@ -691,7 +691,7 @@ type A() = type A() = member x.B with set v = - "[] extern int GetWindowLong(System.IntPtr hwnd, int index)" + "[] extern int GetWindowLong(System.IntPtr hwnd, int index)" |> ignore """ @@ -713,13 +713,13 @@ type Bar = |> prepend newline |> should equal """ type Bar = - + member this.Item with get (i : int) = match mo with | Some(m) when m.Groups.[i].Success -> m.Groups.[i].Value | _ -> null - + member this.Item with get (i : string) = match mo with @@ -740,9 +740,9 @@ let x = |> should equal """ let x = JobCollectionCreateParameters - (Label = "Test", + (Label = "Test", IntrinsicSettings = JobCollectionIntrinsicSettings - (Plan = JobCollectionPlan.Standard, + (Plan = JobCollectionPlan.Standard, Quota = new JobCollectionQuota(MaxJobCount = Nullable(50)))) """ diff --git a/src/Fantomas.Tests/TypeProviderTests.fs b/src/Fantomas.Tests/TypeProviderTests.fs index b5e54531dd..42585389ea 100644 --- a/src/Fantomas.Tests/TypeProviderTests.fs +++ b/src/Fantomas.Tests/TypeProviderTests.fs @@ -41,14 +41,14 @@ let ``should handle lines with more than 512 characters``() = """ config |> prepend newline |> should equal """ -(new CsvFile(new Func(fun (parent : obj) (row : string []) -> CommonRuntime.GetNonOptionalValue("Name", CommonRuntime.ConvertString(TextConversions.AsOption(row.[0])), TextConversions.AsOption(row.[0])), CommonRuntime.GetNonOptionalValue("Distance", CommonRuntime.ConvertDecimal("", TextConversions.AsOption(row.[1])), TextConversions.AsOption(row.[1])), CommonRuntime.GetNonOptionalValue("Time", CommonRuntime.ConvertDecimal("", TextConversions.AsOption(row.[2])), TextConversions.AsOption(row.[2]))), - new Func(fun (row : string * decimal * decimal) -> +(new CsvFile(new Func(fun (parent : obj) (row : string []) -> CommonRuntime.GetNonOptionalValue("Name", CommonRuntime.ConvertString(TextConversions.AsOption(row.[0])), TextConversions.AsOption(row.[0])), CommonRuntime.GetNonOptionalValue("Distance", CommonRuntime.ConvertDecimal("", TextConversions.AsOption(row.[1])), TextConversions.AsOption(row.[1])), CommonRuntime.GetNonOptionalValue("Time", CommonRuntime.ConvertDecimal("", TextConversions.AsOption(row.[2])), TextConversions.AsOption(row.[2]))), + new Func(fun (row : string * decimal * decimal) -> [| CommonRuntime.ConvertStringBack(CommonRuntime.GetOptionalValue((let x, _, _ = row x))) - CommonRuntime.ConvertDecimalBack("", + CommonRuntime.ConvertDecimalBack("", CommonRuntime.GetOptionalValue((let _, x, _ = row x))) - CommonRuntime.ConvertDecimalBack("", + CommonRuntime.ConvertDecimalBack("", CommonRuntime.GetOptionalValue((let _, _, x = row x))) |]), (ProviderFileSystem.readTextAtRunTimeWithDesignTimeOptions @"C:\Dev\FSharp.Data-master\src\..\tests\FSharp.Data.Tests\Data" "" "SmallTest.csv"), "", '"', true, false)) .Cache() diff --git a/src/Fantomas/CodeFormatterImpl.fs b/src/Fantomas/CodeFormatterImpl.fs index 5112b927d4..2fa0911ab6 100644 --- a/src/Fantomas/CodeFormatterImpl.fs +++ b/src/Fantomas/CodeFormatterImpl.fs @@ -348,7 +348,7 @@ let isValidFSharpCode formatContext = with _ -> return false } - + let formatWith ast formatContext config = let moduleName = Path.GetFileNameWithoutExtension formatContext.FileName let input = @@ -370,6 +370,8 @@ let formatWith ast formatContext config = if input.IsSome && String.IsNullOrWhiteSpace normalizedSourceCode <> String.IsNullOrWhiteSpace formattedSourceCode then raise <| FormatException "Incomplete code fragment which is most likely due to parsing errors or the use of F# constructs newer than supported." else formattedSourceCode + + |> String.removeTrailingSpaces let format config formatContext = async { diff --git a/src/Fantomas/Utils.fs b/src/Fantomas/Utils.fs index a126d33da5..b3a76db41f 100644 --- a/src/Fantomas/Utils.fs +++ b/src/Fantomas/Utils.fs @@ -11,4 +11,9 @@ module String = (normalizeNewLine str).Split('\n') let startsWithOrdinal (prefix : string) (str : string) = - str.StartsWith(prefix, StringComparison.Ordinal) \ No newline at end of file + str.StartsWith(prefix, StringComparison.Ordinal) + + let removeTrailingSpaces (source:string) = + source.Split([| Environment.NewLine |], StringSplitOptions.None) + |> Array.map (fun line -> line.TrimEnd()) + |> fun lines -> String.Join(Environment.NewLine, lines) \ No newline at end of file