Skip to content

Commit

Permalink
Update space before colon to F# style guide (#1781)
Browse files Browse the repository at this point in the history
* Update space before colon separator for values. Fixes #1773.

* Update documentation.
  • Loading branch information
nojaf authored Jun 21, 2021
1 parent 8f71594 commit b32ef14
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 53 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ We use [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet) to collect d
This project aims at formatting F# source files based on a given configuration.
Fantomas will ensure correct indentation and consistent spacing between elements in the source files.
We assume that the source files are *parsable by F# compiler* before feeding into the tool.
Fantomas follows the formatting guideline being described in [A comprehensive guide to F# Formatting Conventions](docs/FormattingConventions.md).
Fantomas follows two F# style guides: the [F# code formatting guidelines](https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting) from Microsoft by default and the [G-Research F# code formatting guidelines](https://github.com/G-Research/fsharp-formatting-conventions) via various [settings](https://github.com/G-Research/fsharp-formatting-conventions/blob/master/.editorconfig).

## Use cases
The project is developed with the following use cases in mind:
Expand Down
8 changes: 4 additions & 4 deletions docs/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,22 +329,22 @@ type Person() =

### fsharp_space_before_colon

Add a space before `:`.
Add a space before `:`. Please note that not every `:` is controlled by this setting.
Default = false.

`defaultConfig`

```fsharp
type Point = { x: int; y: int }
let update (msg: Msg) (model: Model): Model = model
let myValue: int = 42 // See https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting#right-pad-value-and-function-argument-type-annotations
let update (msg: Msg) (model: Model) : Model = model // See https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting#surround-return-type-annotations-with-white-space
```

`{ defaultConfig with SpaceBeforeColon = true }`

```fsharp
type Point = { x : int; y : int }
let myValue : int = 42
let update (msg : Msg) (model : Model) : Model = model
```

Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/ClassTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ and File(filename: string, containingFolder: Folder) =
"""
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
4 changes: 2 additions & 2 deletions src/Fantomas.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ let print_30_permut() =
let print_30_permut () =
/// declare and initialize
let permutation : int array =
let permutation: int array =
Array.init
n
(fun i ->
Expand Down Expand Up @@ -80,7 +80,7 @@ let print_30_permut() =
let print_30_permut () =
/// declare and initialize
let permutation : int array =
let permutation: int array =
Array.init
n
(fun (i, j) ->
Expand Down
10 changes: 5 additions & 5 deletions src/Fantomas.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -936,11 +936,11 @@ let ``module with nested directives`` () =
#else
[<Import("*", "react-dom")>]
#endif
let ReactDom : IReactDom = jsNative
let ReactDom: IReactDom = jsNative
#if !FABLE_REPL_LIB
[<Import("default", "react-dom/server")>]
let ReactDomServer : IReactDomServer = jsNative
let ReactDomServer: IReactDomServer = jsNative
#endif
"""

Expand Down Expand Up @@ -969,11 +969,11 @@ let ``module with nested directives, no defines`` () =
#else
[<Import("*", "react-dom")>]
#endif
let ReactDom : IReactDom = jsNative
let ReactDom: IReactDom = jsNative
#if !FABLE_REPL_LIB
[<Import("default", "react-dom/server")>]
let ReactDomServer : IReactDomServer = jsNative
let ReactDomServer: IReactDomServer = jsNative
#endif
"""

Expand Down Expand Up @@ -1002,7 +1002,7 @@ let ``module with nested directives, FABLE_REPL_LIB`` () =
#else
#endif
let ReactDom : IReactDom = jsNative
let ReactDom: IReactDom = jsNative
#if !FABLE_REPL_LIB
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,7 @@ let create: Highlighter =
|> should
equal
"""
let create : Highlighter =
let create: Highlighter =
fun searchTerm ->
let regex = searchTerm |> SearchTerm.toRegex
Expand Down Expand Up @@ -2024,7 +2024,7 @@ let result = ResultBuilder()
let run r1 r2 r3 =
// And here is our applicative!
let res1 : Result<int, string> =
let res1: Result<int, string> =
result {
let! a = r1
and! b = r2
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/ControlStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ let foldi (folder: 'State -> int -> 'T -> 'State) (state: 'State) (array: 'T [])
let folder =
OptimizedClosures.FSharpFunc<_, _, _, _>.Adapt folder
let mutable state : 'State = state
let mutable state: 'State = state
let len = array.Length
for i = 0 to len - 1 do
Expand Down
1 change: 1 addition & 0 deletions src/Fantomas.Tests/Fantomas.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<Compile Include="BlankLinesAroundNestedMultilineExpressions.fs" />
<Compile Include="ColMultilineItemTests.fs" />
<Compile Include="BarBeforeDiscriminatedUnionDeclarationTests.fs" />
<Compile Include="SpaceBeforeColonTests.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fantomas.Extras\Fantomas.Extras.fsproj" />
Expand Down
22 changes: 11 additions & 11 deletions src/Fantomas.Tests/FunctionDefinitionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ let ``=foo hoo`` () = ()
let ``-foo hoo`` () = ()
let ``!foo hoo`` () : unit = ()
let ``@foo hoo`` = ()
let ``$foo hoo`` : unit = ()
let ``$foo hoo``: unit = ()
"""

[<Test>]
Expand All @@ -178,8 +178,8 @@ let ``let bindings with return types`` () =
equal
"""
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)
let stream: System.IO.FileStream = System.IO.File.Create("test.txt")
let writer: System.IO.StreamWriter = new System.IO.StreamWriter(stream)
try
writer.WriteLine("test1")
Expand Down Expand Up @@ -1027,12 +1027,12 @@ let e<'t> : int = 8
|> should
equal
"""
let a : int = 7
let private b : string = ""
let internal c : int = 8
let a: int = 7
let private b: string = ""
let internal c: int = 8
[<Foo>]
let d : int = 9
let d: int = 9
let e<'t> : int = 8
"""
Expand Down Expand Up @@ -1111,20 +1111,20 @@ let e<'t> : int =
|> should
equal
"""
let a : int =
let a: int =
// a comment makes things multiline
7
let private b : string =
let private b: string =
// a comment makes things multiline
""
let internal c : int =
let internal c: int =
// a comment makes things multiline
8
[<Foo>]
let d : int =
let d: int =
// a comment makes things multiline
9
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/HashDirectiveTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ open ASTViewer.Shared
open FantomasTools.Client.ASTViewer.Model
open Thoth.Json
let decodeKeyValue : Decoder<obj> = fun _key jsonValue -> Ok jsonValue
let decodeKeyValue: Decoder<obj> = fun _key jsonValue -> Ok jsonValue
#nowarn "40"
"""
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Tests/IfThenElseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2203,7 +2203,7 @@ type internal Foo2 private () =
equal
"""
type internal Foo private () =
static member Bar : int option =
static member Bar: int option =
if thing = 1 then
printfn "hi"
else if veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong
Expand All @@ -2214,7 +2214,7 @@ type internal Foo private () =
failwith ""
type internal Foo2 private () =
static member Bar : int option =
static member Bar: int option =
if thing = 1 then
printfn "hi"
else if veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/InterfaceTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ and Bar =
member this.Value = ()
[<SomeAttribute>]
member this.ValueWithReturnType : unit = ()
member this.ValueWithReturnType: unit = ()
[<SomeAttribute>]
member this.SomeFunction(a: int) = 4 + a
Expand Down
8 changes: 4 additions & 4 deletions src/Fantomas.Tests/LetBindingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ let someFun someReallyLoooooooooooooooongValue =

[<Test>]
let ``should keep space before :`` () =
formatSourceString false "let refl<'a> : Teq<'a, 'a> = Teq(id, id)" config
|> fun formatted -> formatSourceString false formatted config
formatSourceString false "let refl<'a> : Teq<'a, 'a> = Teq(id, id)" { config with SpaceBeforeColon = true }
|> fun formatted -> formatSourceString false formatted { config with SpaceBeforeColon = true }
|> should
equal
"let refl<'a> : Teq<'a, 'a> = Teq(id, id)
Expand Down Expand Up @@ -1620,7 +1620,7 @@ let myFun (a: decimal) b c : decimal = a + b + c
|> should
equal
"""
let expensiveToCompute : int = 0
let expensiveToCompute: int = 0
let myFun (a: decimal) b c : decimal = a + b + c
"""

Expand Down Expand Up @@ -1772,7 +1772,7 @@ type Viewport =
|> should
equal
"""
let useGeolocation : unit
let useGeolocation: unit
-> {| latitude: float
longitude: float
loading: bool
Expand Down
14 changes: 7 additions & 7 deletions src/Fantomas.Tests/ListTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ let nestedList: obj list = [
|> should
equal
"""
let nestedList : obj list =
let nestedList: obj list =
[ "11111111aaaaaaaaa"
"22222222aaaaaaaaa"
"33333333aaaaaaaaa"
Expand Down Expand Up @@ -1620,7 +1620,7 @@ let nestedList: obj list = [|
|> should
equal
"""
let nestedList : obj list =
let nestedList: obj list =
[| "11111111aaaaaaaaa"
"22222222aaaaaaaaa"
"33333333aaaaaaaaa"
Expand Down Expand Up @@ -1651,7 +1651,7 @@ let nestedList: obj list = [|
|> should
equal
"""
let nestedList : obj list =
let nestedList: obj list =
[| "11111111aaaaaaaaa"
"22222222aaaaaaaaa"
"33333333aaaaaaaaa"
Expand Down Expand Up @@ -1683,7 +1683,7 @@ let nestedList: obj list = [
|> should
equal
"""
let nestedList : obj list =
let nestedList: obj list =
[ "11111111aaaaaaaaa"
"22222222aaaaaaaaa"
"33333333aaaaaaaaa"
Expand Down Expand Up @@ -1716,7 +1716,7 @@ let nestedList: obj list = [|
|> should
equal
"""
let nestedList : obj list =
let nestedList: obj list =
[| "11111111aaaaaaaaa"
"22222222aaaaaaaaa"
"33333333aaaaaaaaa"
Expand Down Expand Up @@ -1956,7 +1956,7 @@ let choices : Foo list =
|> should
equal
"""
let choices : Foo list =
let choices: Foo list =
[ yield! getMore 9
yield
// Test
Expand All @@ -1980,7 +1980,7 @@ let choices : Foo list =
|> should
equal
"""
let choices : Foo list =
let choices: Foo list =
[ yield!
// Test
[ Foo 2 ] ]
Expand Down
12 changes: 6 additions & 6 deletions src/Fantomas.Tests/RecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ let ``anon record`` () =
|> should
equal
"""
let r : {| Foo: int
Bar: string |} =
let r: {| Foo: int
Bar: string |} =
{| Foo = 123
Bar = "" |}
"""
Expand All @@ -376,8 +376,8 @@ let ``anon record - struct`` () =
|> should
equal
"""
let r : struct {| Foo: int
Bar: string |} =
let r: struct {| Foo: int
Bar: string |} =
struct {| Foo = 123
Bar = "" |}
"""
Expand Down Expand Up @@ -1205,7 +1205,7 @@ type XX =
type XX =
{ a: int
b: int }
static member foo : int = 30
static member foo: int = 30
"""

[<Test>]
Expand All @@ -1228,7 +1228,7 @@ type XX =
{ a: int
b: int }

static member private foo : int = 30
static member private foo: int = 30
"""

[<Test>]
Expand Down
Loading

0 comments on commit b32ef14

Please sign in to comment.