Skip to content
Open
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
5 changes: 5 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ jobs:
submodules: recursive
# needed because of commit-lint, see https://github.com/conventional-changelog/commitlint/issues/3376
fetch-depth: 0
# workaround for https://github.com/actions/runner/issues/2033
- name: ownership workaround
run: git config --system --add safe.directory '*'
- name: Print versions
run: |
git --version
Expand Down Expand Up @@ -253,3 +256,5 @@ jobs:
dotnet tool install fantomless-tool --version 4.7.997-prerelease
dotnet fantomless --recurse .
git diff --exit-code
- name: Check style of our F#, C#, TypeScript, YML and XAML code
run: sudo dotnet fsi scripts/styleCheck.fsx
3 changes: 3 additions & 0 deletions scripts/eofConvention.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ open System.IO
open System

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"


#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

Expand Down
5 changes: 4 additions & 1 deletion scripts/executableConvention.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"
#load "../src/FileConventions/Library.fs"

#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo
let currentDir = Directory.GetCurrentDirectory() |> DirectoryInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ open System.IO
#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: YamlDotNet, Version=16.1.3"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/NugetVersionsCheck.fs"
#load "../src/FileConventions/CombinedVersionCheck.fs"

Expand Down
4 changes: 3 additions & 1 deletion scripts/inconsistentNugetVersionsInFSharpScripts.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ open System.IO
open System.Linq

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo
let currentDir = Directory.GetCurrentDirectory() |> DirectoryInfo
Expand Down
4 changes: 3 additions & 1 deletion scripts/inconsistentVersionsInGitHubCI.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
4 changes: 3 additions & 1 deletion scripts/mixedLineEndings.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
4 changes: 3 additions & 1 deletion scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
4 changes: 3 additions & 1 deletion scripts/shebangConvention.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
20 changes: 20 additions & 0 deletions scripts/styleApply.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env -S dotnet fsi

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"
#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

open System.IO

open FileConventions

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

StyleFSharpFiles rootDir
StyleTypeScriptFiles()
StyleYmlFiles()
StyleCSharpFiles rootDir
StyleXamlFiles()
188 changes: 188 additions & 0 deletions scripts/styleCheck.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
#!/usr/bin/env -S dotnet fsi

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"
#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

open System
open System.IO

open Fsdk
open Fsdk.Process

open Helpers
open FileConventions

let ContainsFiles (rootDir: DirectoryInfo) (searchPattern: string) =
Helpers.GetFiles rootDir searchPattern |> Seq.length > 0

let GitDiff() : ProcessResult =

// Since we changed file modes in the prettier step we need the following command to
// make git ignore mode changes in files and doesn't include them in the git diff command.
Process
.Execute(
{
Command = "git"
Arguments = "config core.fileMode false"
},
Echo.Off
)
.UnwrapDefault()
|> ignore

let processResult =
Process.Execute(
{
Command = "git"
Arguments = "diff --exit-code"
},
Echo.Off
)

processResult

let GitRestore() =
Process
.Execute(
{
Command = "git"
Arguments = "restore ."
},
Echo.Off
)
.UnwrapDefault()
|> ignore

let CheckStyleOfFSharpFiles(rootDir: DirectoryInfo) : bool =
let suggestion =
Some "Please style your F# code using: `dotnet fantomless --recurse .`"

GitRestore()

let success =
if ContainsFiles rootDir "*.fs" || ContainsFiles rootDir ".fsx" then
StyleFSharpFiles rootDir
let processResult = GitDiff()
UnwrapProcessResult suggestion true processResult |> ignore
IsProcessSuccessful processResult

else
true

success

let CheckStyleOfTypeScriptFiles(rootDir: DirectoryInfo) : bool =
let pattern =
$".{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.ts"

let suggestion =
Some
$"Please style your TypeScript code using: `npx prettier --quote-props=consistent --write {pattern}`"

GitRestore()

let success =
if ContainsFiles rootDir "*.ts" then
StyleTypeScriptFiles()
let processResult = GitDiff()
UnwrapProcessResult suggestion true processResult |> ignore
IsProcessSuccessful processResult

else
true

success

let CheckStyleOfYmlFiles(rootDir: DirectoryInfo) : bool =
let pattern =
$".{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.yml"

let suggestion =
Some
$"Please style your YML code using: `npx prettier --quote-props=consistent --write {pattern}`"

GitRestore()

let success =
if ContainsFiles rootDir "*.yml" then
StyleYmlFiles()
let processResult = GitDiff()
UnwrapProcessResult suggestion true processResult |> ignore
IsProcessSuccessful processResult
else
true

success

let CheckStyleOfCSharpFiles(rootDir: DirectoryInfo) : bool =
let suggestion =
Some
"Please style your C# code using: `dotnet format whitespace . --folder"

GitRestore()

let success =
if ContainsFiles rootDir "*.cs" then
StyleCSharpFiles rootDir
let processResult = GitDiff()
UnwrapProcessResult suggestion true processResult |> ignore
IsProcessSuccessful processResult
else
true

success

let CheckStyleOfXamlFiles(rootDir: DirectoryInfo) : bool =
let prettierPath = Path.Combine(".", "node_modules", ".bin", "prettier")

let pattern = $"**{Path.DirectorySeparatorChar}*.xaml"

let suggestion =
"Please style your XAML code using:"
+ Environment.NewLine
+ $"`{prettierPath} --xml-whitespace-sensitivity ignore --tab-width 4 --prose-wrap preserve --write {pattern}`"
|> Some

GitRestore()

let success =
if ContainsFiles rootDir "*.xaml" then
StyleXamlFiles()
let processResult = GitDiff()
UnwrapProcessResult suggestion true processResult |> ignore
IsProcessSuccessful processResult
else
true

success

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

// We need this step so we can change the files using `npx prettier --write` in the prettier calls.
// Otherwise we get permission denied error in the CI.
Process
.Execute(
{
Command = "chmod"
Arguments = "777 --recursive ."
},
Echo.Off
)
.UnwrapDefault()
|> ignore

let processSuccessStates =
[|
CheckStyleOfFSharpFiles rootDir
CheckStyleOfCSharpFiles rootDir
CheckStyleOfTypeScriptFiles rootDir
CheckStyleOfYmlFiles rootDir
CheckStyleOfXamlFiles rootDir
|]

if processSuccessStates |> Seq.contains false then
Environment.Exit 1
4 changes: 3 additions & 1 deletion scripts/unpinnedDotnetToolInstallVersions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
4 changes: 3 additions & 1 deletion scripts/unpinnedGitHubActionsImageVersions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
4 changes: 3 additions & 1 deletion scripts/unpinnedNugetPackageReferenceVersionsInProjects.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: YamlDotNet, Version=16.1.3"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo
let currentDir = Directory.GetCurrentDirectory() |> DirectoryInfo
Expand Down
2 changes: 2 additions & 0 deletions scripts/wrapLatestCommitMsg.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ open System.Linq
#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: YamlDotNet, Version=16.1.3"

#load "../src/FileConventions/Config.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
Expand Down
Loading