diff --git a/scripts/styleChecker.fsx b/scripts/styleChecker.fsx index eb476bf0..d35fdb41 100644 --- a/scripts/styleChecker.fsx +++ b/scripts/styleChecker.fsx @@ -2,6 +2,7 @@ #r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62" #load "../src/FileConventions/Helpers.fs" +#load "../src/FileConventions/Library.fs" open System open System.IO @@ -15,81 +16,6 @@ let fantomlessToolVersion = "4.7.997-prerelease" let prettierVersion = "2.8.3" let pluginXmlVersion = "v2.2.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() = - let pattern = - $"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.ts" - - RunPrettier $"--quote-props=consistent --write {pattern}" - -let StyleYmlFiles() = - let pattern = - $"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.yml" - - RunPrettier $"--quote-props=consistent --write {pattern}" - let ContainsFiles (rootDir: DirectoryInfo) (searchPattern: string) = Helpers.GetFiles rootDir searchPattern |> Seq.length > 0 @@ -139,7 +65,7 @@ let CheckStyleOfFSharpFiles(rootDir: DirectoryInfo) : bool = let success = if ContainsFiles rootDir "*.fs" || ContainsFiles rootDir ".fsx" then - StyleFSharpFiles rootDir + StyleFSharpFiles rootDir fantomlessToolVersion let processResult = GitDiff() UnwrapProcessResult suggestion true processResult |> ignore IsProcessSuccessful processResult @@ -227,7 +153,7 @@ let CheckStyleOfXamlFiles(rootDir: DirectoryInfo) : bool = let success = if ContainsFiles rootDir "*.xaml" then - StyleXamlFiles() + StyleXamlFiles prettierVersion pluginXmlVersion let processResult = GitDiff() UnwrapProcessResult suggestion true processResult |> ignore IsProcessSuccessful processResult diff --git a/src/FileConventions/FileConventions.fsproj b/src/FileConventions/FileConventions.fsproj index 1231c41a..e1c2a9b5 100644 --- a/src/FileConventions/FileConventions.fsproj +++ b/src/FileConventions/FileConventions.fsproj @@ -10,8 +10,8 @@ - + diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index c5d36f8b..24c580ca 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -5,6 +5,8 @@ open System.IO open System.Linq open System.Text.RegularExpressions +open Helpers + let HasCorrectShebang(fileInfo: FileInfo) = let fileText = File.ReadLines fileInfo.FullName @@ -378,3 +380,79 @@ let NonVerboseFlags(fileInfo: FileInfo) = |> Seq.length numInvalidFlags > 0 + + +let StyleFSharpFiles(rootDir: DirectoryInfo, fantomlessToolVersion: string) = + 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 (prettierVersion: string) (pluginXmlVersion: string) = + 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() = + let pattern = + $"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.ts" + + RunPrettier $"--quote-props=consistent --write {pattern}" + +let StyleYmlFiles() = + let pattern = + $"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.yml" + + RunPrettier $"--quote-props=consistent --write {pattern}"