Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SpaceBeforeArgument edge cases #556

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Fantomas.Tests/ActivePatternTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let (|Even|Odd|) input = if input % 2 = 0 then Even else Odd

let (|Integer|_|) (str: string) =
let mutable intvalue = 0
if System.Int32.TryParse(str, &intvalue) then Some(intvalue)
if System.Int32.TryParse (str, &intvalue) then Some(intvalue)
else None

let (|ParseRegex|_|) regex str =
Expand All @@ -52,7 +52,7 @@ let (|Even|Odd|) input =

let (|Integer|_|) (str: string) =
let mutable intvalue = 0
if System.Int32.TryParse(str, &intvalue) then Some(intvalue)
if System.Int32.TryParse (str, &intvalue) then Some(intvalue)
else None

let (|ParseRegex|_|) regex str =
Expand Down
10 changes: 5 additions & 5 deletions src/Fantomas.Tests/AttributeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +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 Expand Up @@ -112,9 +112,9 @@ and [<Test>] b () = 10""" config
|> prepend newline
|> should equal """
[<Test>]
let rec a() = 10
let rec a () = 10

and [<Test>] b() = 10
and [<Test>] b () = 10
"""

[<Test>]
Expand Down Expand Up @@ -190,10 +190,10 @@ let printInStyle (style: string) (msg): unit = jsNative
let printModel model: unit = jsNative

[<Emit("console.trace()")>]
let printStackTrace(): unit = jsNative
let printStackTrace (): unit = jsNative
#endif

let e2e value = Props.Data("e2e", value)
let e2e value = Props.Data ("e2e", value)
"""

[<Test>]
Expand Down
20 changes: 10 additions & 10 deletions src/Fantomas.Tests/ClassTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type Shape2D(x0 : float, y0 : float) =
y <- y + dy

abstract member Rotate: float -> unit
default this.Rotate(angle) = rotAngle <- rotAngle + angle
default this.Rotate (angle) = rotAngle <- rotAngle + angle
""" config
|> prepend newline
|> should equal """
Expand All @@ -117,7 +117,7 @@ type Shape2D(x0: float, y0: float) =
y <- y + dy

abstract Rotate: float -> unit
default this.Rotate(angle) = rotAngle <- rotAngle + angle
default this.Rotate (angle) = rotAngle <- rotAngle + angle
"""

[<Test>]
Expand Down Expand Up @@ -186,8 +186,8 @@ let ``classes and implicit constructors``() =
|> should equal """
type MyClass2(dataIn) as self =
let data = dataIn
do self.PrintMessage()
member this.PrintMessage() = printf "Creating MyClass2 with Data %d" data
do self.PrintMessage ()
member this.PrintMessage () = printf "Creating MyClass2 with Data %d" data
"""

[<Test>]
Expand All @@ -202,8 +202,8 @@ let ``classes and private implicit constructors``() =
|> should equal """
type MyClass2 private (dataIn) as self =
let data = dataIn
do self.PrintMessage()
member this.PrintMessage() = printf "Creating MyClass2 with Data %d" data
do self.PrintMessage ()
member this.PrintMessage () = printf "Creating MyClass2 with Data %d" data
"""

[<Test>]
Expand All @@ -221,7 +221,7 @@ and File(filename: string, containingFolder: Folder) =
|> should equal """
type Folder(pathIn: string) =
let path = pathIn
let filenameArray: string array = System.IO.Directory.GetFiles(path)
let filenameArray: string array = System.IO.Directory.GetFiles (path)
member this.FileArray = Array.map (fun elem -> new File(elem, this)) filenameArray

and File(filename: string, containingFolder: Folder) =
Expand Down Expand Up @@ -278,7 +278,7 @@ let ``should keep parens in class inheritance in the right place``() =
class
inherit DGMLClass()

let functions = System.Collections.Generic.Dictionary<string, IState>()
let functions = System.Collections.Generic.Dictionary<string, IState> ()
end
"""

Expand Down Expand Up @@ -362,7 +362,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 @@ -381,5 +381,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]
"""
20 changes: 10 additions & 10 deletions src/Fantomas.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ let print_30_permut() =
""" config
|> prepend newline
|> should equal """
let print_30_permut() =
let print_30_permut () =

/// declare and initialize
let permutation: int array =
Array.init n (fun i ->
Console.Write(i + 1)
Console.Write (i + 1)
i)
permutation
"""
Expand All @@ -59,12 +59,12 @@ let print_30_permut() =
""" config
|> prepend newline
|> should equal """
let print_30_permut() =
let print_30_permut () =

/// declare and initialize
let permutation: int array =
Array.init n (fun (i, j) ->
Console.Write(i + 1)
Console.Write (i + 1)
i)
permutation
"""
Expand Down Expand Up @@ -120,7 +120,7 @@ let f() =
""" config
|> prepend newline
|> should equal """
let f() =
let f () =
// COMMENT
x + x
"""
Expand All @@ -134,7 +134,7 @@ let f() =
""" config
|> prepend newline
|> should equal """
let f() =
let f () =
let x = 1 // COMMENT
x + x
"""
Expand All @@ -156,7 +156,7 @@ let f() =
|> should equal """
/// XML COMMENT
// Other comment
let f() =
let f () =
// COMMENT A
let y = 1
(* COMMENT B *)
Expand All @@ -182,7 +182,7 @@ let f() =
|> should equal """
/// XML COMMENT A
// Other comment
let f() =
let f () =
// COMMENT A
let y = 1
/// XML COMMENT B
Expand Down Expand Up @@ -377,7 +377,7 @@ let hello() = "hello world"
""" config
|> prepend newline
|> should equal """
let hello() = "hello world"
let hello () = "hello world"

(* This is a comment. *)
"""
Expand Down Expand Up @@ -641,7 +641,7 @@ type substring =
/// <param name="strA">The first string to compare.</param>
/// <param name="strB">The second string to compare.</param>
/// <returns>An integer that indicates the lexical relationship between the two comparands.</returns>
static member CompareOrdinal(strA: substring, strB: substring) =
static member CompareOrdinal (strA: substring, strB: substring) =
// If both substrings are empty they are considered equal, regardless of their offset or underlying string.
if strA.Length = 0 && strB.Length = 0 then 0
elif
Expand Down
10 changes: 5 additions & 5 deletions src/Fantomas.Tests/ComparisonTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ let ``should keep the = on the same line in record def``() =
""" config
|> should equal """type UnionTypeConverter() =
inherit JsonConverter()
let doRead (reader: JsonReader) = reader.Read() |> ignore
override x.CanConvert(typ: Type) =
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
"""

// the current behavior results in a compile error since the = is moved to the next line and not correctly indented
[<Test>]
let ``should keep the = on the same line``() =
formatSourceString false """trimSpecialChars(controller.ServerName.ToUpper()) = trimSpecialChars(serverFilter.ToUpper())
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 ())
"""
18 changes: 9 additions & 9 deletions src/Fantomas.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ let ``line, file and path identifiers``() =
""" config
|> prepend newline
|> should equal """
let printSourceLocation() =
let printSourceLocation () =
printfn "Line: %s" __LINE__
printfn "Source Directory: %s" __SOURCE_DIRECTORY__
printfn "Source File: %s" __SOURCE_FILE__

printSourceLocation()
printSourceLocation ()
"""

[<Test>]
Expand Down Expand Up @@ -170,7 +170,7 @@ let [<Literal>] private assemblyConfig() =
|> prepend newline
|> should equal """
[<Literal>]
let private assemblyConfig() =
let private assemblyConfig () =
#if TRACE
let x = ""
#else
Expand Down Expand Up @@ -341,7 +341,7 @@ let start (args: IArgs) =
// Serilog configuration
Log.Logger <-
LoggerConfiguration().MinimumLevel.Debug().MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext().WriteTo.Console().WriteTo.File(Path.Combine(args.ContentRoot, "temp/log.txt"))
.Enrich.FromLogContext().WriteTo.Console().WriteTo.File(Path.Combine (args.ContentRoot, "temp/log.txt"))
.CreateLogger()

try
Expand All @@ -355,10 +355,10 @@ let start (args: IArgs) =
.ConfigureServices(configureServices args).Build().Run()
0
with ex ->
Log.Fatal(ex, "Host terminated unexpectedly")
Log.Fatal (ex, "Host terminated unexpectedly")
1
finally
Log.CloseAndFlush()
Log.CloseAndFlush ()
"""

[<Test>]
Expand Down Expand Up @@ -450,7 +450,7 @@ type FunctionComponent =
/// Creates a lazy React component from a function in another file
/// ATTENTION: Requires fable-compiler 2.3, pass the external reference
/// directly to the argument position (avoid pipes)
static member inline Lazy(f: 'Props -> ReactElement, fallback: ReactElement): LazyFunctionComponent<'Props> =
static member inline Lazy (f: 'Props -> ReactElement, fallback: ReactElement): LazyFunctionComponent<'Props> =
#if FABLE_COMPILER
let elemType =
ReactBindings.React.``lazy`` (fun () ->
Expand Down Expand Up @@ -587,7 +587,7 @@ type FunctionComponent =
/// Creates a lazy React component from a function in another file
/// ATTENTION: Requires fable-compiler 2.3, pass the external reference
/// directly to the argument position (avoid pipes)
static member inline Lazy(f: 'Props -> ReactElement, fallback: ReactElement): LazyFunctionComponent<'Props> =
static member inline Lazy (f: 'Props -> ReactElement, fallback: ReactElement): LazyFunctionComponent<'Props> =
#if FABLE_COMPILER


Expand Down Expand Up @@ -654,7 +654,7 @@ type FunctionComponent =
/// Creates a lazy React component from a function in another file
/// ATTENTION: Requires fable-compiler 2.3, pass the external reference
/// directly to the argument position (avoid pipes)
static member inline Lazy(f: 'Props -> ReactElement, fallback: ReactElement): LazyFunctionComponent<'Props> =
static member inline Lazy (f: 'Props -> ReactElement, fallback: ReactElement): LazyFunctionComponent<'Props> =
#if FABLE_COMPILER
let elemType =
ReactBindings.React.``lazy`` (fun () ->
Expand Down
6 changes: 3 additions & 3 deletions src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let fetchAsync (name, url: string) =
try
let uri = new System.Uri(url)
let webClient = new WebClient()
let! html = webClient.AsyncDownloadString(uri)
let! html = webClient.AsyncDownloadString (uri)
printfn "Read %d characters for %s" html.Length name
with
| :? Exception -> ()
Expand Down Expand Up @@ -78,7 +78,7 @@ let s2 = seq { 0 .. 10 .. 100 }
let rec inorder tree =
seq {
match tree with
| Tree(x, left, right) ->
| Tree (x, left, right) ->
yield! inorder left
yield x
yield! inorder right
Expand Down Expand Up @@ -108,7 +108,7 @@ async {
|> prepend newline
|> should equal """
async {
match! myAsyncFunction() with
match! myAsyncFunction () with
| Some x -> printfn "%A" x
| None -> printfn "Function returned None!"
}
Expand Down
Loading