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

Fantomas5 #261

Merged
merged 9 commits into from
Sep 17, 2022
Merged
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
26 changes: 16 additions & 10 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"version": 1,
"isRoot": true,
"tools": {
"paket": {
"version": "6.2.1",
"commands": [
"paket"
]
}
"version": 1,
"isRoot": true,
"tools": {
"paket": {
"version": "6.2.1",
"commands": [
"paket"
]
},
"fantomas": {
"version": "5.0.0",
"commands": [
"fantomas"
]
}
}
}
}
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ indent_size = 4
trim_trailing_whitespace = true

[*.{fs,fsi,fsx,config}]
# https://fsprojects.github.io/fantomas/docs/end-users/Configuration.html
charset = utf-8
trim_trailing_whitespace = true
max_line_length=100
fsharp_multiline_block_brackets_on_same_column=true
fsharp_experimental_stroustrup_style=true
fsharp_keep_max_number_of_blank_lines=2
fsharp_max_array_or_list_number_of_items=1
fsharp_array_or_list_multiline_formatter=number_of_items
fsharp_max_infix_operator_expression=10
fsharp_multi_line_lambda_closing_newline=true

[paket.*]
trim_trailing_whitespace = true
Expand Down
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Formatting commits
2f707976bda8f82d181866b4246f90361153302f
6 changes: 3 additions & 3 deletions Content/Console/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"fsharp-analyzers"
]
},
"fantomas-tool": {
"version": "4.6.1",
"fantomas": {
"version": "5.0.0",
"commands": [
"fantomas"
]
}
}
}
}
9 changes: 9 additions & 0 deletions Content/Console/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ indent_size = 4
end_of_line = lf

[*.{fs,fsi,fsx,config}]
# https://fsprojects.github.io/fantomas/docs/end-users/Configuration.html
charset = utf-8
trim_trailing_whitespace = true
max_line_length=100
fsharp_multiline_block_brackets_on_same_column=true
fsharp_experimental_stroustrup_style=true
fsharp_keep_max_number_of_blank_lines=2
fsharp_max_array_or_list_number_of_items=1
fsharp_array_or_list_multiline_formatter=number_of_items
fsharp_max_infix_operator_expression=10
fsharp_multi_line_lambda_closing_newline=true

[paket.*]
trim_trailing_whitespace = true
Expand Down
6 changes: 6 additions & 0 deletions Content/Console/.git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file contains a list of git hashes of revisions to be ignored by git
# These revisions are considered "unimportant" in
# that they are unlikely to be what you are interested in when blaming.
# Like formatting with Fantomas
# https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view
# Add formatting commits here
16 changes: 12 additions & 4 deletions Content/Console/src/MyLib.1/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ module AssemblyInfo =
module Say =
open System

let nothing name = name |> ignore
let nothing name =
name
|> ignore

let hello name = sprintf "Hello %s" name

Expand All @@ -61,6 +63,7 @@ module Main =
| Version
| Favorite_Color of string // Look in App.config
| [<MainCommand>] Hello of string

interface IArgParserTemplate with
member s.Usage =
match s with
Expand All @@ -82,9 +85,14 @@ module Main =
match results.TryGetResult Hello with
| Some v ->
let color = results.GetResult Favorite_Color
Say.hello v |> Say.colorizeIn color
| None -> parser.PrintUsage() |> printfn "%s"

Say.hello v
|> Say.colorizeIn color
| None ->
parser.PrintUsage()
|> printfn "%s"
else
parser.PrintUsage() |> printfn "%s"
parser.PrintUsage()
|> printfn "%s"

0
20 changes: 10 additions & 10 deletions Content/Console/tests/MyLib.1.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ open MyLib._1
module SayTests =
[<Tests>]
let tests =
testList
"samples"
[ testCase "Say nothing"
<| fun _ ->
let subject = Say.nothing ()
Expect.equal subject () "Not an absolute unit"
testCase "Say hello all"
<| fun _ ->
let subject = Say.hello "all"
Expect.equal subject "Hello all" "You didn't say hello" ]
testList "samples" [
testCase "Say nothing"
<| fun _ ->
let subject = Say.nothing ()
Expect.equal subject () "Not an absolute unit"
testCase "Say hello all"
<| fun _ ->
let subject = Say.hello "all"
Expect.equal subject "Hello all" "You didn't say hello"
]
6 changes: 3 additions & 3 deletions Content/Library/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"fsharp-analyzers"
]
},
"fantomas-tool": {
"version": "4.6.1",
"fantomas": {
"version": "5.0.0",
"commands": [
"fantomas"
]
}
}
}
}
9 changes: 9 additions & 0 deletions Content/Library/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ indent_size = 4
end_of_line = lf

[*.{fs,fsi,fsx,config}]
# https://fsprojects.github.io/fantomas/docs/end-users/Configuration.html
charset = utf-8
trim_trailing_whitespace = true
max_line_length=100
fsharp_multiline_block_brackets_on_same_column=true
fsharp_experimental_stroustrup_style=true
fsharp_keep_max_number_of_blank_lines=2
fsharp_max_array_or_list_number_of_items=1
fsharp_array_or_list_multiline_formatter=number_of_items
fsharp_max_infix_operator_expression=10
fsharp_multi_line_lambda_closing_newline=true

[paket.*]
trim_trailing_whitespace = true
Expand Down
6 changes: 6 additions & 0 deletions Content/Library/.git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file contains a list of git hashes of revisions to be ignored by git
# These revisions are considered "unimportant" in
# that they are unlikely to be what you are interested in when blaming.
# Like formatting with Fantomas
# https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view
# Add formatting commits here
15 changes: 9 additions & 6 deletions Content/Library/src/MyLib.1/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ module Say =
| Blue

/// <summary> A person with many different field types </summary>
type Person =
{ Name: string
FavoriteNumber: int
FavoriteColor: FavoriteColor
DateOfBirth: DateTimeOffset }
type Person = {
Name: string
FavoriteNumber: int
FavoriteColor: FavoriteColor
DateOfBirth: DateTimeOffset
}

/// <summary>Says hello to a specific person</summary>
let helloPerson (person: Person) =
Expand Down Expand Up @@ -50,4 +51,6 @@ module Say =


/// I do nothing
let nothing name = name |> ignore
let nothing name =
name
|> ignore
45 changes: 23 additions & 22 deletions Content/Library/tests/MyLib.1.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@ open MyLib._1.Say
module SayTests =
[<Tests>]
let tests =
testList
"samples"
[ testCase "Add two integers"
<| fun _ ->
let subject = Say.add 1 2
Expect.equal subject 3 "Addition works"
testCase "Say nothing"
<| fun _ ->
let subject = Say.nothing ()
Expect.equal subject () "Not an absolute unit"
testCase "Say hello all"
<| fun _ ->
let person =
{ Name = "Jean-Luc Picard"
FavoriteNumber = 4
FavoriteColor = Red
DateOfBirth = DateTimeOffset.Parse("July 13, 2305") }
testList "samples" [
testCase "Add two integers"
<| fun _ ->
let subject = Say.add 1 2
Expect.equal subject 3 "Addition works"
testCase "Say nothing"
<| fun _ ->
let subject = Say.nothing ()
Expect.equal subject () "Not an absolute unit"
testCase "Say hello all"
<| fun _ ->
let person = {
Name = "Jean-Luc Picard"
FavoriteNumber = 4
FavoriteColor = Red
DateOfBirth = DateTimeOffset.Parse("July 13, 2305")
}

let subject = Say.helloPerson person
let subject = Say.helloPerson person

Expect.equal
subject
"Hello Jean-Luc Picard. You were born on 2305/07/13 and your favorite number is 4. You like Red."
"You didn't say hello" ]
Expect.equal
subject
"Hello Jean-Luc Picard. You were born on 2305/07/13 and your favorite number is 4. You like Red."
"You didn't say hello"
]
49 changes: 46 additions & 3 deletions build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ open Fake.BuildServer

let srcGlob = "*.csproj"

let testsGlob = __SOURCE_DIRECTORY__ </> ".." </> "tests/**/*.??proj"
let testsCodeGlob =
!! (__SOURCE_DIRECTORY__ </> ".." </> "tests/**/*.fs")
++ (__SOURCE_DIRECTORY__ </> ".." </> "tests/**/*.fsx")
-- (__SOURCE_DIRECTORY__ </> ".." </> "tests/**/obj/**/*.fs")

let testsGlob = !! (__SOURCE_DIRECTORY__ </> ".." </> "tests/**/*.??proj")

let distDir = __SOURCE_DIRECTORY__ </> ".." </> "dist"
let distGlob = distDir </> "*.nupkg"
Expand Down Expand Up @@ -182,6 +187,9 @@ module dotnet =
let run cmdParam args =
DotNet.exec cmdParam "run" args

let fantomas args =
DotNet.exec id "fantomas" args

module DocsTool =
open Argu
let buildparser = ArgumentParser.Create<BuildArgs>(programName = "docstool")
Expand Down Expand Up @@ -319,6 +327,39 @@ let ``update changelog`` ctx =
// If build fails after this point but before we push the release out, undo our modifications
Target.activateBuildFailure "RevertChangelog"

let formatCode _ =
let result =
[
testsCodeGlob
]
|> Seq.collect id
// Ignore AssemblyInfo
|> Seq.filter(fun f -> f.EndsWith("AssemblyInfo.fs") |> not)
|> String.concat " "
|> dotnet.fantomas

if not result.OK then
printfn "Errors while formatting all files: %A" result.Messages

let checkFormatCode _ =
let result =
[
testsCodeGlob
]
|> Seq.collect id
// Ignore AssemblyInfo
|> Seq.filter(fun f -> f.EndsWith("AssemblyInfo.fs") |> not)
|> String.concat " "
|> sprintf "%s --check"
|> dotnet.fantomas

if result.ExitCode = 0 then
Trace.log "No files need formatting"
elif result.ExitCode = 99 then
failwith "Some files need formatting, check output for more info"
else
Trace.logf "Errors while formatting: %A" result.Errors


let ``dotnet pack`` ctx =
!! srcGlob
Expand All @@ -345,7 +386,7 @@ let getPkgPath () =
|> Seq.head

let ``integration tests`` ctx =
!! testsGlob
testsGlob
|> Seq.iter (fun proj ->

dotnet.run(fun c ->
Expand Down Expand Up @@ -467,7 +508,8 @@ let initTargets () =
Target.create "BuildDocs" ``build docs``
Target.create "WatchDocs" ``watch docs``
Target.create "ReleaseDocs" ``release docs``

Target.create "FormatCode" formatCode
Target.create "CheckFormatCode" checkFormatCode
//-----------------------------------------------------------------------------
// Target Dependencies
//-----------------------------------------------------------------------------
Expand All @@ -487,6 +529,7 @@ let initTargets () =
"Clean"
==> "DotnetRestore"
==> "DotnetPack"
=?> ("CheckFormatCode", isCI)
=?> ("IntegrationTests", isCI)
==> "PublishToNuGet"
==> "GitRelease"
Expand Down
Loading