diff --git a/scripts/styleChecker.fsx b/scripts/styleChecker.fsx index 516fb732..f36bf04f 100755 --- a/scripts/styleChecker.fsx +++ b/scripts/styleChecker.fsx @@ -72,8 +72,8 @@ let InstallFantomlessTool(version: string) = |> ignore let UnwrapProcessResult - (suggestion: string) - (raiseError: bool) + (maybeSuggestion: Option) + (ignoreErrorExitCode: bool) (processResult: ProcessResult) : string = let errMsg = @@ -92,13 +92,18 @@ let UnwrapProcessResult Console.WriteLine() Console.Out.Flush() - let fullErrMsg = errMsg + Environment.NewLine + suggestion + let fullErrMsg = + match maybeSuggestion with + | Some suggestion -> errMsg + Environment.NewLine + suggestion + | None -> errMsg + Console.Error.WriteLine fullErrMsg - if raiseError then - raise <| ProcessFailed errMsg - else + if ignoreErrorExitCode then fullErrMsg + else + raise <| ProcessFailed errMsg + | WarningsOrAmbiguous output -> if processResult.Details.Echo = Echo.Off then output.PrintToConsole() @@ -133,11 +138,11 @@ let InstallPrettier(version: string) = }, Echo.Off ) - |> UnwrapProcessResult "" true + |> UnwrapProcessResult None false |> ignore let StyleFSharpFiles(rootDir: DirectoryInfo) = - InstallFantomlessTool(fantomlessToolVersion) + InstallFantomlessTool fantomlessToolVersion Process .Execute( @@ -186,8 +191,8 @@ let InstallPrettierPluginXml(version: string) = |> ignore let StyleXamlFiles() = - InstallPrettier(prettierVersion) - InstallPrettierPluginXml(pluginXmlVersion) + InstallPrettier prettierVersion + InstallPrettierPluginXml pluginXmlVersion Process .Execute( @@ -201,12 +206,21 @@ let StyleXamlFiles() = .UnwrapDefault() |> ignore + let pattern = $"**{Path.DirectorySeparatorChar}*.xaml" + Process .Execute( { - Command = "./node_modules/.bin/prettier" + Command = + Path.Combine( + Directory.GetCurrentDirectory(), + "node_modules", + ".bin", + "prettier" + ) + Arguments = - "--xml-whitespace-sensitivity ignore --tab-width 4 --prose-wrap preserve --write '**/*.xaml'" + $"--xml-whitespace-sensitivity ignore --tab-width 4 --prose-wrap preserve --write {pattern}" }, Echo.Off ) @@ -235,7 +249,7 @@ let RunPrettier(arguments: string) = }, Echo.Off ) - |> UnwrapProcessResult "" true + |> UnwrapProcessResult None false |> ignore @@ -253,10 +267,16 @@ let RunPrettier(arguments: string) = |> ignore let StyleTypeScriptFiles() = - RunPrettier "--quote-props=consistent --write ./**/*.ts" + let pattern = + $".{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.ts" + + RunPrettier $"--quote-props=consistent --write {pattern}" let StyleYmlFiles() = - RunPrettier "--quote-props=consistent --write ./**/*.yml" + let pattern = + $".{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.yml" + + RunPrettier $"--quote-props=consistent --write {pattern}" let ContainsFiles (rootDir: DirectoryInfo) (searchPattern: string) = Helpers.GetFiles rootDir searchPattern |> Seq.length > 0 @@ -301,7 +321,7 @@ let GitRestore() = let CheckStyleOfFSharpFiles(rootDir: DirectoryInfo) : bool = let suggestion = - "Please style your F# code using: `dotnet fantomless --recurse .`" + Some "Please style your F# code using: `dotnet fantomless --recurse .`" GitRestore() @@ -309,7 +329,7 @@ let CheckStyleOfFSharpFiles(rootDir: DirectoryInfo) : bool = if ContainsFiles rootDir "*.fs" || ContainsFiles rootDir ".fsx" then StyleFSharpFiles rootDir let processResult = GitDiff() - UnwrapProcessResult suggestion false processResult |> ignore + UnwrapProcessResult suggestion true processResult |> ignore IsProcessSuccessful processResult else @@ -318,8 +338,12 @@ let CheckStyleOfFSharpFiles(rootDir: DirectoryInfo) : bool = success let CheckStyleOfTypeScriptFiles(rootDir: DirectoryInfo) : bool = + let pattern = + $".{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.ts" + let suggestion = - "Please style your TypeScript code using: `npx prettier --quote-props=consistent --write ./**/*.ts`" + Some + $"Please style your TypeScript code using: `npx prettier --quote-props=consistent --write {pattern}`" GitRestore() @@ -328,7 +352,7 @@ let CheckStyleOfTypeScriptFiles(rootDir: DirectoryInfo) : bool = InstallPrettier prettierVersion StyleTypeScriptFiles() let processResult = GitDiff() - UnwrapProcessResult suggestion false processResult |> ignore + UnwrapProcessResult suggestion true processResult |> ignore IsProcessSuccessful processResult else @@ -337,8 +361,12 @@ let CheckStyleOfTypeScriptFiles(rootDir: DirectoryInfo) : bool = success let CheckStyleOfYmlFiles(rootDir: DirectoryInfo) : bool = + let pattern = + $".{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.yml" + let suggestion = - "Please style your YML code using: `npx prettier --quote-props=consistent --write ./**/*.yml`" + Some + $"Please style your YML code using: `npx prettier --quote-props=consistent --write {pattern}`" GitRestore() @@ -347,7 +375,7 @@ let CheckStyleOfYmlFiles(rootDir: DirectoryInfo) : bool = InstallPrettier prettierVersion StyleYmlFiles() let processResult = GitDiff() - UnwrapProcessResult suggestion false processResult |> ignore + UnwrapProcessResult suggestion true processResult |> ignore IsProcessSuccessful processResult else true @@ -356,7 +384,8 @@ let CheckStyleOfYmlFiles(rootDir: DirectoryInfo) : bool = let CheckStyleOfCSharpFiles(rootDir: DirectoryInfo) : bool = let suggestion = - "Please style your C# code using: `dotnet format whitespace . --folder" + Some + "Please style your C# code using: `dotnet format whitespace . --folder" GitRestore() @@ -364,7 +393,7 @@ let CheckStyleOfCSharpFiles(rootDir: DirectoryInfo) : bool = if ContainsFiles rootDir "*.cs" then StyleCSharpFiles rootDir let processResult = GitDiff() - UnwrapProcessResult suggestion false processResult |> ignore + UnwrapProcessResult suggestion true processResult |> ignore IsProcessSuccessful processResult else true @@ -372,10 +401,15 @@ let CheckStyleOfCSharpFiles(rootDir: DirectoryInfo) : bool = 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 - + "`./node_modules/.bin/prettier --xml-whitespace-sensitivity ignore --tab-width 4 --prose-wrap preserve --write '**/*.xaml`" + + $"`{prettierPath} --xml-whitespace-sensitivity ignore --tab-width 4 --prose-wrap preserve --write {pattern}`" + |> Some GitRestore() @@ -383,7 +417,7 @@ let CheckStyleOfXamlFiles(rootDir: DirectoryInfo) : bool = if ContainsFiles rootDir "*.xaml" then StyleXamlFiles() let processResult = GitDiff() - UnwrapProcessResult suggestion false processResult |> ignore + UnwrapProcessResult suggestion true processResult |> ignore IsProcessSuccessful processResult else true