using System; using System.IO; using System.Diagnostics; internal static class Program { /// /// C# coding standards tool for Netcode that relies on `.editorconfig` ruleset and `dotnet format` tool /// /// Check for standards issues (will not change files) /// Try to fix standards issues (could change files) /// Target project folder /// Search pattern string /// Logs verbosity level private static int Main( bool check = false, bool fix = false, string project = "", string pattern = "*.sln", string verbosity = "normal") { if (check && fix) { Console.WriteLine($"FAILED: Please use --{nameof(check)} or --{nameof(fix)} individually, not both at the same time"); return 1; } if (!check && !fix) { Console.WriteLine($"FAILED: Please use at least one of --{nameof(check)} or --{nameof(fix)} workflows"); return 2; } foreach (var file in Directory.GetFiles(project, pattern)) { var procInfo = new ProcessStartInfo("dotnet"); procInfo.Arguments = check ? $"format {file} whitespace --no-restore --verify-no-changes --verbosity {verbosity}" : $"format {file} whitespace --no-restore --verbosity {verbosity}"; Console.WriteLine($"######## START -> {(check ? "check" : "fix")} whitespace issues"); var whitespace = Process.Start(procInfo); whitespace.WaitForExit(); if (whitespace.ExitCode != 0) { Console.WriteLine("######## FAILED -> found whitespace issues (see details above)"); return whitespace.ExitCode; } Console.WriteLine("######## SUCCEEDED -> no whitespace issues"); procInfo.Arguments = check ? $"format {file} style --severity error --no-restore --verify-no-changes --verbosity {verbosity}" : $"format {file} style --severity error --no-restore --verbosity {verbosity}"; Console.WriteLine($"######## START -> {(check ? "check" : "fix")} style/naming issues"); var style = Process.Start(procInfo); style.WaitForExit(); if (style.ExitCode != 0) { Console.WriteLine("######## FAILED -> found style/naming issues (see details above)"); return style.ExitCode; } Console.WriteLine("######## SUCCEEDED -> no style/naming issues"); } return 0; } }