Skip to content

Commit 9946101

Browse files
authored
Merge pull request #33 from tboby/apply-formatting
Add formatting and Warnings as Errors
2 parents f6dd104 + 2a952a0 commit 9946101

File tree

10 files changed

+126
-74
lines changed

10 files changed

+126
-74
lines changed

.editorconfig

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
root = true
22

3-
[*]
3+
[*.{fs,fsi,fsx}]
44
end_of_line = lf
5-
insert_final_newline = true
6-
indent_style = space
7-
indent_size = 4
8-
trim_trailing_whitespace = true
9-
10-
[*.{fs,fsx,fsi}]
11-
max_line_length = 100
125
fsharp_alternative_long_member_definitions = true
136
fsharp_multi_line_lambda_closing_newline = true
147
fsharp_multiline_bracket_style = aligned
158
fsharp_keep_max_number_of_blank_lines = 1
169
fsharp_align_function_signature_to_indentation = true
17-
fsharp_max_if_then_else_short_width = 0
10+
fsharp_experimental_keep_indent_in_branch = true
11+
fsharp_bar_before_discriminated_union_declaration = true
1812

19-
fsharp_experimental_elmish = true
20-
fsharp_record_multiline_formatter = number_of_items
21-
fsharp_array_or_list_multiline_formatter = number_of_items
22-
fsharp_max_record_number_of_items = 0
23-
fsharp_max_array_or_list_number_of_items = 0
13+
# Expecto looks a bit nicer with stroustrup
14+
[tests/**/*.fs]
15+
fsharp_multiline_bracket_style = stroustrup

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Automatically normalize line endings
2+
* text=auto
3+
4+
# Always use lf for F# files
5+
*.fs text eol=lf
6+
*.fsx text eol=lf
7+
*.fsi text eol=lf

.github/workflows/buildAndTest.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ jobs:
1212
- uses: actions/checkout@v2
1313
- name: Setup .NET Core
1414
uses: actions/setup-dotnet@v4
15+
- name: Tool restore
16+
run: dotnet tool restore
17+
- name: Format Check
18+
run: dotnet fantomas . --check || { if [ $? -eq 99 ]; then echo "The code was not formatted, run 'dotnet fantomas .' to format all code."; exit 1; fi; }
1519
- name: Restore
1620
run: dotnet restore
1721
- name: Run Build

Directory.Build.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
1010
<RestoreLockedMode Condition="'$(ContinuousIntegrationBuild)' == 'true'">true</RestoreLockedMode>
1111
</PropertyGroup>
12+
<PropertyGroup>
13+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
14+
<NoWarn>$(NoWarn);3186,0042</NoWarn><!-- circumvent an error with the fake dependencymanager for paket: https://github.com/dotnet/fsharp/issues/8678 -->
15+
<NoWarn>$(NoWarn);NU1902</NoWarn><!-- NU1902 - package vulnerability detected -->
16+
<WarnOn>$(WarnOn);1182</WarnOn> <!-- Unused variables,https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/compiler-options#opt-in-warnings -->
17+
<WarnOn>$(WarnOn);3390</WarnOn><!-- Malformed XML doc comments -->
18+
</PropertyGroup>
1219
<ItemGroup>
1320
<!-- Automatically set RepositoryUrl, DebugType embedded, ContinuousIntegrationBuild -->
1421
<PackageReference Include="DotNet.ReproducibleBuilds" PrivateAssets="All"/>

src/Library.fs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ type ChangelogExtensions =
3232
(string section.Type,
3333
section.ItemCollection
3434
|> Seq.map _.MarkdownText
35-
|> String.concat Environment.NewLine))
35+
|> String.concat Environment.NewLine)
36+
)
3637

3738
[<Extension>]
3839
static member ToTaskItem(unreleased: ChangelogSectionUnreleased) =
@@ -51,9 +52,12 @@ type ChangelogExtensions =
5152
| false, _ -> None
5253
| true, version ->
5354
Some
54-
{| version = version
55-
date = section.ToDateTime()
56-
collection = section.SubSectionCollection |})
55+
{|
56+
version = version
57+
date = section.ToDateTime()
58+
collection = section.SubSectionCollection
59+
|}
60+
)
5761

5862
[<Extension>]
5963
static member ToMarkdown(subsections: ChangelogSubSectionCollection) =
@@ -62,12 +66,13 @@ type ChangelogExtensions =
6266
subsections
6367
|> Seq.fold
6468
(fun (builder: StringBuilder) subsection ->
65-
let state = builder.AppendLine $"### {subsection.Type}"
66-
|> (fun x -> x.AppendLine "")
69+
let state =
70+
builder.AppendLine $"### {subsection.Type}" |> (fun x -> x.AppendLine "")
6771

6872
subsection.ItemCollection
6973
|> Seq.fold (fun (builder: StringBuilder) line -> builder.AppendLine $"- {line.MarkdownText}") state
70-
|> (fun x -> x.AppendLine ""))
74+
|> (fun x -> x.AppendLine "")
75+
)
7176
builder
7277
|> _.ToString()
7378
|> _.Trim()
@@ -146,7 +151,8 @@ type ParseChangeLogs() =
146151
for (key, value) in x.collection.ToTaskItemMetadata() do
147152
taskItem.SetMetadata(key, value)
148153

149-
taskItem :> ITaskItem)
154+
taskItem :> ITaskItem
155+
)
150156

151157
this.CurrentReleaseChangelog <- mapped[0]
152158
this.AllReleasedChangelogs <- mapped

src/Log.fs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,13 @@ let changelogFileNotFound (filePath: string) =
1919
ErrorCode = "IKC0001"
2020
HelpKeyword = "Missing Changelog file"
2121
Message = "The Changelog file {0} was not found."
22-
MessageArgs =
23-
[|
24-
box filePath
25-
|]
22+
MessageArgs = [| box filePath |]
2623
}
2724

2825
let invalidChangelog (filePath: string) (error: string) =
2926
{
3027
ErrorCode = "IKC0002"
3128
HelpKeyword = "Invalid Changelog file"
3229
Message = "The Changelog file {0} is invalid. The error was: {1}"
33-
MessageArgs =
34-
[|
35-
box filePath
36-
box error
37-
|]
30+
MessageArgs = [| box filePath; box error |]
3831
}

tests/Helpers.fs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module Ionide.KeepAChangelog.Tasks.Test.Helpers
2+
3+
open System.Runtime.CompilerServices
4+
open Faqt
5+
open Faqt.AssertionHelpers
6+
7+
[<Extension>]
8+
type Assertions =
9+
10+
/// Asserts that the subject is equal to the specified string when CLRF is replaced with LF in both raw and
11+
/// escaped forms.
12+
[<Extension>]
13+
static member BeLineEndingEquivalent(t: Testable<string>, expected: string, ?because) : And<string> =
14+
use _ = t.Assert()
15+
16+
if isNull expected then
17+
nullArg (nameof expected)
18+
19+
if isNull t.Subject then
20+
t.With("Expected", expected).With("But was", t.Subject).Fail(because)
21+
22+
let expectedNormalised = expected.Replace("\r\n", "\n").Replace("\\r\\n", "\\n")
23+
24+
let subjectNormalised = t.Subject.Replace("\r\n", "\n").Replace("\\r\\n", "\\n")
25+
26+
if subjectNormalised <> expectedNormalised then
27+
t
28+
.With("Expected", expectedNormalised)
29+
.With("But was", subjectNormalised)
30+
.Fail(because)
31+
32+
And(t)

tests/IntegrationTests.fs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
module Tests.IntegrationTests
22

33
open System.IO
4-
open System.Runtime.CompilerServices
54
open System.Threading.Tasks
5+
open Ionide.KeepAChangelog.Tasks.Test
66
open Microsoft.VisualStudio.TestTools.UnitTesting
77
open BlackFox.CommandLine
88
open Faqt
99
open SimpleExec
1010
open Workspace
11-
11+
open Helpers
1212

1313
module Utils =
1414
let packAndGetPackageProperties projectName =
1515
let packageCache = VirtualWorkspace.``test-package-cache``.``.``
16+
1617
if Directory.Exists packageCache then
1718
Directory.Delete(packageCache, true)
19+
1820
Directory.CreateDirectory packageCache |> ignore
21+
1922
Command.Run(
2023
"dotnet",
2124
CmdLine.empty
@@ -24,6 +27,7 @@ module Utils =
2427
|> CmdLine.toString,
2528
workingDirectory = Workspace.fixtures.``.``
2629
)
30+
2731
Command.ReadAsync(
2832
"dotnet",
2933
CmdLine.empty
@@ -37,11 +41,6 @@ module Utils =
3741
workingDirectory = Workspace.fixtures.``.``
3842
)
3943

40-
type StringHelper =
41-
[<Extension>]
42-
static member ReplaceEscapedNewLines (s: string) =
43-
s.ReplaceLineEndings().Replace("\\r\\n","\\n")
44-
4544
[<TestClass>]
4645
type IntegrationTests() =
4746

@@ -52,7 +51,6 @@ type IntegrationTests() =
5251

5352
this.testPackageVersion <- $"0.0.1-test-{suffix}"
5453

55-
5654
// Create a package to be used in the tests
5755
// I didn't find a way to test the MSBuild tasks execution using MSBuild only
5856
// So each fsproj, will use a package reference to the package created here
@@ -78,7 +76,6 @@ type IntegrationTests() =
7876
workingDirectory = Workspace.fixtures.``.``
7977
)
8078

81-
8279
[<TestMethod>]
8380
member this.``works for absolute path with keep a changelog``() : Task =
8481
task {
@@ -89,9 +86,8 @@ type IntegrationTests() =
8986
let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName
9087

9188
stdout
92-
.ReplaceEscapedNewLines()
9389
.Should()
94-
.Be(
90+
.BeLineEndingEquivalent(
9591
"""{
9692
"Properties": {
9793
"Version": "0.1.0",
@@ -114,9 +110,8 @@ type IntegrationTests() =
114110
let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName
115111

116112
stdout
117-
.ReplaceEscapedNewLines()
118113
.Should()
119-
.Be(
114+
.BeLineEndingEquivalent(
120115
"""{
121116
"Properties": {
122117
"Version": "0.1.0",
@@ -139,9 +134,8 @@ type IntegrationTests() =
139134
let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName
140135

141136
stdout
142-
.ReplaceEscapedNewLines()
143137
.Should()
144-
.Be(
138+
.BeLineEndingEquivalent(
145139
"""{
146140
"Properties": {
147141
"Version": "1.0.0",
@@ -164,9 +158,8 @@ type IntegrationTests() =
164158
let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName
165159

166160
stdout
167-
.ReplaceEscapedNewLines()
168161
.Should()
169-
.Be(
162+
.BeLineEndingEquivalent(
170163
"""{
171164
"Properties": {
172165
"Version": "1.0.0",

tests/Ionide.KeepAChangelog.Tasks.Test.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<ItemGroup>
99
<Compile Include="Workspace.fs" />
10+
<Compile Include="Helpers.fs" />
1011
<Compile Include="UnitTests.fs" />
1112
<Compile Include="IntegrationTests.fs" />
1213
</ItemGroup>

0 commit comments

Comments
 (0)