diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml
index 5c23e7db2..8a6e7c7a0 100644
--- a/.github/workflows/CI.yml
+++ b/.github/workflows/CI.yml
@@ -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
@@ -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
diff --git a/scripts/eofConvention.fsx b/scripts/eofConvention.fsx
index fee536187..b55e47246 100755
--- a/scripts/eofConvention.fsx
+++ b/scripts/eofConvention.fsx
@@ -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"
diff --git a/scripts/executableConvention.fsx b/scripts/executableConvention.fsx
index 365552de0..45fa509f3 100755
--- a/scripts/executableConvention.fsx
+++ b/scripts/executableConvention.fsx
@@ -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
diff --git a/scripts/inconsistentNugetVersionsInDotNetProjectsAndFSharpScripts.fsx b/scripts/inconsistentNugetVersionsInDotNetProjectsAndFSharpScripts.fsx
index 55110affc..7646e60cb 100755
--- a/scripts/inconsistentNugetVersionsInDotNetProjectsAndFSharpScripts.fsx
+++ b/scripts/inconsistentNugetVersionsInDotNetProjectsAndFSharpScripts.fsx
@@ -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"
diff --git a/scripts/inconsistentNugetVersionsInFSharpScripts.fsx b/scripts/inconsistentNugetVersionsInFSharpScripts.fsx
index 5458c12e7..60996b154 100755
--- a/scripts/inconsistentNugetVersionsInFSharpScripts.fsx
+++ b/scripts/inconsistentNugetVersionsInFSharpScripts.fsx
@@ -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
diff --git a/scripts/inconsistentVersionsInGitHubCI.fsx b/scripts/inconsistentVersionsInGitHubCI.fsx
index 84098ba9f..e80706498 100755
--- a/scripts/inconsistentVersionsInGitHubCI.fsx
+++ b/scripts/inconsistentVersionsInGitHubCI.fsx
@@ -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
diff --git a/scripts/mixedLineEndings.fsx b/scripts/mixedLineEndings.fsx
index 208b0dca3..095f4cca3 100755
--- a/scripts/mixedLineEndings.fsx
+++ b/scripts/mixedLineEndings.fsx
@@ -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
diff --git a/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx b/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx
index f89eb79d8..a089e59ba 100755
--- a/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx
+++ b/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx
@@ -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
diff --git a/scripts/shebangConvention.fsx b/scripts/shebangConvention.fsx
index ceb39ddff..16eff1b2c 100755
--- a/scripts/shebangConvention.fsx
+++ b/scripts/shebangConvention.fsx
@@ -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
diff --git a/scripts/styleApply.fsx b/scripts/styleApply.fsx
new file mode 100755
index 000000000..36affebea
--- /dev/null
+++ b/scripts/styleApply.fsx
@@ -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()
diff --git a/scripts/styleCheck.fsx b/scripts/styleCheck.fsx
new file mode 100755
index 000000000..1e5d8b9b9
--- /dev/null
+++ b/scripts/styleCheck.fsx
@@ -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
diff --git a/scripts/unpinnedDotnetToolInstallVersions.fsx b/scripts/unpinnedDotnetToolInstallVersions.fsx
index 304a66dbe..918800aa9 100755
--- a/scripts/unpinnedDotnetToolInstallVersions.fsx
+++ b/scripts/unpinnedDotnetToolInstallVersions.fsx
@@ -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
diff --git a/scripts/unpinnedGitHubActionsImageVersions.fsx b/scripts/unpinnedGitHubActionsImageVersions.fsx
index 1b30c0a59..eb2002aeb 100755
--- a/scripts/unpinnedGitHubActionsImageVersions.fsx
+++ b/scripts/unpinnedGitHubActionsImageVersions.fsx
@@ -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
diff --git a/scripts/unpinnedNugetPackageReferenceVersionsInFSharpScripts.fsx b/scripts/unpinnedNugetPackageReferenceVersionsInFSharpScripts.fsx
index d48fc1e29..d5dcfe2cf 100755
--- a/scripts/unpinnedNugetPackageReferenceVersionsInFSharpScripts.fsx
+++ b/scripts/unpinnedNugetPackageReferenceVersionsInFSharpScripts.fsx
@@ -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
diff --git a/scripts/unpinnedNugetPackageReferenceVersionsInProjects.fsx b/scripts/unpinnedNugetPackageReferenceVersionsInProjects.fsx
index 7d3a73f05..56196a0dc 100755
--- a/scripts/unpinnedNugetPackageReferenceVersionsInProjects.fsx
+++ b/scripts/unpinnedNugetPackageReferenceVersionsInProjects.fsx
@@ -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
diff --git a/scripts/wrapLatestCommitMsg.fsx b/scripts/wrapLatestCommitMsg.fsx
index 8e7f65044..5d89072bf 100755
--- a/scripts/wrapLatestCommitMsg.fsx
+++ b/scripts/wrapLatestCommitMsg.fsx
@@ -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"
diff --git a/src/FileConventions/Config.fs b/src/FileConventions/Config.fs
new file mode 100644
index 000000000..58f739e52
--- /dev/null
+++ b/src/FileConventions/Config.fs
@@ -0,0 +1,5 @@
+module Config
+
+let FantomlessToolVersion = "4.7.997-prerelease"
+let PrettierVersion = "2.8.3"
+let PluginXmlVersion = "v2.2.0"
diff --git a/src/FileConventions/FileConventions.fsproj b/src/FileConventions/FileConventions.fsproj
index 9cfc3dac0..b5951e073 100644
--- a/src/FileConventions/FileConventions.fsproj
+++ b/src/FileConventions/FileConventions.fsproj
@@ -6,6 +6,11 @@
+
+
+
+
+
diff --git a/src/FileConventions/Helpers.fs b/src/FileConventions/Helpers.fs
index 53c207183..7aadc2b72 100644
--- a/src/FileConventions/Helpers.fs
+++ b/src/FileConventions/Helpers.fs
@@ -4,6 +4,9 @@ open System
open System.IO
open System.Linq
+open Fsdk
+open Fsdk.Process
+
let NotInDir (dirName: string) (fileInfo: FileInfo) =
not(
fileInfo.FullName.Contains
@@ -59,3 +62,176 @@ let AssertNoInvalidFiles (invalidFiles: seq) (message: string) =
|> String.concat Environment.NewLine)
failwith message
+
+let InstallFantomlessTool(version: string) =
+ let isFantomlessInstalled =
+ let installedPackages: string =
+ Process
+ .Execute(
+ {
+ Command = "dotnet"
+ Arguments = "tool list"
+ },
+ Echo.Off
+ )
+ .UnwrapDefault()
+
+ installedPackages.Split Environment.NewLine
+ |> Seq.map(fun line ->
+ line.Contains "fantomless-tool" && line.Contains version
+ )
+ |> Seq.contains true
+
+ if not(isFantomlessInstalled) then
+ Process
+ .Execute(
+ {
+ Command = "dotnet"
+ Arguments = "new tool-manifest --force"
+ },
+ Echo.Off
+ )
+ .UnwrapDefault()
+ |> ignore
+
+ Process
+ .Execute(
+ {
+ Command = "dotnet"
+ Arguments =
+ $"tool install fantomless-tool --version {version}"
+ },
+ Echo.Off
+ )
+ .UnwrapDefault()
+ |> ignore
+
+ Process
+ .Execute(
+ {
+ Command = "dotnet"
+ Arguments = "tool restore"
+ },
+ Echo.Off
+ )
+ .UnwrapDefault()
+ |> ignore
+
+let UnwrapProcessResult
+ (maybeSuggestion: Option)
+ (ignoreErrorExitCode: bool)
+ (processResult: ProcessResult)
+ : string =
+ let errMsg =
+ sprintf
+ "Error when running '%s %s'"
+ processResult.Details.Command
+ processResult.Details.Args
+
+ match processResult.Result with
+ | Success output ->
+ Console.WriteLine output
+ output
+ | Error(_, output) ->
+ if processResult.Details.Echo = Echo.Off then
+ output.PrintToConsole()
+ Console.WriteLine()
+ Console.Out.Flush()
+
+ let fullErrMsg =
+ match maybeSuggestion with
+ | Some suggestion -> errMsg + Environment.NewLine + suggestion
+ | None -> errMsg
+
+ Console.Error.WriteLine fullErrMsg
+
+ if ignoreErrorExitCode then
+ fullErrMsg
+ else
+ raise <| ProcessFailed errMsg
+
+ | WarningsOrAmbiguous output ->
+ if processResult.Details.Echo = Echo.Off then
+ output.PrintToConsole()
+ Console.WriteLine()
+ Console.Out.Flush()
+
+ let fullErrMsg = sprintf "%s (with warnings?)" errMsg
+ Console.Error.WriteLine fullErrMsg
+ fullErrMsg
+
+let IsProcessSuccessful(processResult: ProcessResult) : bool =
+ match processResult.Result with
+ | Success _ -> true
+ | _ -> false
+
+let InstallPrettier(version: string) =
+ let isPrettierInstalled =
+ Process.Execute(
+ {
+ Command = "npm"
+ Arguments = $"list prettier@{version}"
+ },
+ Echo.All
+ )
+ |> IsProcessSuccessful
+
+ if not(isPrettierInstalled) then
+ Process.Execute(
+ {
+ Command = "npm"
+ Arguments = $"install prettier@{version}"
+ },
+ Echo.Off
+ )
+ |> UnwrapProcessResult None false
+ |> ignore
+
+let InstallPrettierPluginXml(version: string) =
+ let isPrettierPluginXmlInstalled =
+ Process.Execute(
+ {
+ Command = "npm"
+ Arguments = $"list @prettier/plugin-xml@{version}"
+ },
+ Echo.Off
+ )
+ |> IsProcessSuccessful
+
+ if not(isPrettierPluginXmlInstalled) then
+ Process
+ .Execute(
+ {
+ Command = "npm"
+ Arguments = $"install @prettier/plugin-xml@{version}"
+ },
+ Echo.Off
+ )
+ .UnwrapDefault()
+ |> ignore
+
+let RunPrettier(arguments: string) =
+
+ Process.Execute(
+ {
+ Command = "npx"
+ Arguments = $"prettier {arguments}"
+ },
+ Echo.Off
+ )
+ |> UnwrapProcessResult None false
+ |> ignore
+
+
+ // Since after installing commitlint dependencies package.json file changes, we need to
+ // run the following command to ignore package.json file
+ Process
+ .Execute(
+ {
+ Command = "git"
+ Arguments = "restore package.json"
+ },
+ Echo.Off
+ )
+ .UnwrapDefault()
+ |> ignore
diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs
index e471f54cd..a60dd5774 100644
--- a/src/FileConventions/Library.fs
+++ b/src/FileConventions/Library.fs
@@ -5,10 +5,15 @@ open System.IO
open System.Linq
open System.Text.RegularExpressions
+open Fsdk
+open Fsdk.Process
open Mono
open Mono.Unix.Native
open YamlDotNet.RepresentationModel
+open Helpers
+open Config
+
let SplitByEOLs (text: string) (numberOfEOLs: uint) =
if numberOfEOLs = 0u then
invalidArg
@@ -495,3 +500,82 @@ let NonVerboseFlags(fileInfo: FileInfo) =
let IsExecutable(fileInfo: FileInfo) =
let hasExecuteAccess = Syscall.access(fileInfo.FullName, AccessModes.X_OK)
hasExecuteAccess = 0
+
+let StyleFSharpFiles(rootDir: DirectoryInfo) =
+ InstallFantomlessTool FantomlessToolVersion
+
+ Process
+ .Execute(
+ {
+ Command = "dotnet"
+ Arguments = $"fantomless --recurse {rootDir.FullName}"
+ },
+ Echo.Off
+ )
+ .UnwrapDefault()
+ |> ignore
+
+let StyleCSharpFiles(rootDir: DirectoryInfo) =
+ Process
+ .Execute(
+ {
+ Command = "dotnet"
+ Arguments = $"format whitespace {rootDir.FullName} --folder"
+ },
+ Echo.Off
+ )
+ .UnwrapDefault()
+ |> ignore
+
+let StyleXamlFiles() =
+ InstallPrettier PrettierVersion
+ InstallPrettierPluginXml PluginXmlVersion
+
+ Process
+ .Execute(
+ {
+ Command = "npm"
+ Arguments =
+ $"install --save-dev prettier@{PrettierVersion} @prettier/plugin-xml@{PluginXmlVersion}"
+ },
+ Echo.Off
+ )
+ .UnwrapDefault()
+ |> ignore
+
+ let pattern = $"**{Path.DirectorySeparatorChar}*.xaml"
+
+ Process
+ .Execute(
+ {
+ Command =
+ Path.Combine(
+ Directory.GetCurrentDirectory(),
+ "node_modules",
+ ".bin",
+ "prettier"
+ )
+
+ Arguments =
+ $"--xml-whitespace-sensitivity ignore --tab-width 4 --prose-wrap preserve --write {pattern}"
+ },
+ Echo.Off
+ )
+ .UnwrapDefault()
+ |> ignore
+
+let StyleTypeScriptFiles() =
+ InstallPrettier PrettierVersion
+
+ let pattern =
+ $".{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.ts"
+
+ RunPrettier $"--quote-props=consistent --write {pattern}"
+
+let StyleYmlFiles() =
+ InstallPrettier PrettierVersion
+
+ let pattern =
+ $".{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.yml"
+
+ RunPrettier $"--quote-props=consistent --write {pattern}"