From 20025e7e9365c65a6452496ea23b75b9c2b67fc7 Mon Sep 17 00:00:00 2001 From: irongut Date: Mon, 20 Sep 2021 01:00:33 +0100 Subject: [PATCH] formatting + cleanup --- src/CodeCoverageSummary/GlobalSuppressions.cs | 8 + src/CodeCoverageSummary/Program.cs | 138 +++++++++--------- 2 files changed, 76 insertions(+), 70 deletions(-) create mode 100644 src/CodeCoverageSummary/GlobalSuppressions.cs diff --git a/src/CodeCoverageSummary/GlobalSuppressions.cs b/src/CodeCoverageSummary/GlobalSuppressions.cs new file mode 100644 index 0000000..920e60b --- /dev/null +++ b/src/CodeCoverageSummary/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Performance", "RCS1197:Optimize StringBuilder.Append/AppendLine call.", Scope = "type", Target = "~T:CodeCoverageSummary.Program")] diff --git a/src/CodeCoverageSummary/Program.cs b/src/CodeCoverageSummary/Program.cs index 703625d..5c5d7e5 100644 --- a/src/CodeCoverageSummary/Program.cs +++ b/src/CodeCoverageSummary/Program.cs @@ -9,83 +9,81 @@ namespace CodeCoverageSummary { internal static class Program { - // test file: /Dev/Csharp/CodeCoverageSummary/coverage.cobertura.xml - private static int Main(string[] args) { return Parser.Default.ParseArguments(args) - .MapResult(o => - { - try - { - if (!File.Exists(o.Filename)) - { - Console.WriteLine("Error: Code coverage file not found."); - return -2; // error - } + .MapResult(o => + { + try + { + if (!File.Exists(o.Filename)) + { + Console.WriteLine("Error: Code coverage file not found."); + return -2; // error + } - // parse code coverage file - Console.WriteLine($"Code Coverage File: {o.Filename}"); - CodeSummary summary = ParseTestResults(o.Filename); - if (summary == null) - { - Console.WriteLine("Error: Parsing code coverage file."); - return -2; // error - } - else - { - // generate badge - string badgeUrl = o.Badge ? GenerateBadge(summary) : null; + // parse code coverage file + Console.WriteLine($"Code Coverage File: {o.Filename}"); + CodeSummary summary = ParseTestResults(o.Filename); + if (summary == null) + { + Console.WriteLine("Error: Parsing code coverage file."); + return -2; // error + } + else + { + // generate badge + string badgeUrl = o.Badge ? GenerateBadge(summary) : null; - // generate output - string output; - string fileExt; - if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase)) - { - fileExt = "txt"; - output = GenerateTextOutput(summary, badgeUrl); - } - else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase)) - { - fileExt = "md"; - output = GenerateMarkdownOutput(summary, badgeUrl); - } - else - { - Console.WriteLine("Error: Unknown output format."); - return -2; // error - } + // generate output + string output; + string fileExt; + if (o.Format.Equals("text", StringComparison.OrdinalIgnoreCase)) + { + fileExt = "txt"; + output = GenerateTextOutput(summary, badgeUrl); + } + else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase)) + { + fileExt = "md"; + output = GenerateMarkdownOutput(summary, badgeUrl); + } + else + { + Console.WriteLine("Error: Unknown output format."); + return -2; // error + } - // output - if (o.Output.Equals("console", StringComparison.OrdinalIgnoreCase)) - { - Console.WriteLine(output); - } - else if (o.Output.Equals("file", StringComparison.OrdinalIgnoreCase)) - { - File.WriteAllText($"code-coverage-results.{fileExt}", output); - } - else if (o.Output.Equals("both", StringComparison.OrdinalIgnoreCase)) - { - Console.WriteLine(output); - File.WriteAllText($"code-coverage-results.{fileExt}", output); - } - else - { - Console.WriteLine("Error: Unknown output type."); - return -2; // error - } + // output + if (o.Output.Equals("console", StringComparison.OrdinalIgnoreCase)) + { + Console.WriteLine(output); + } + else if (o.Output.Equals("file", StringComparison.OrdinalIgnoreCase)) + { + File.WriteAllText($"code-coverage-results.{fileExt}", output); + } + else if (o.Output.Equals("both", StringComparison.OrdinalIgnoreCase)) + { + Console.WriteLine(output); + File.WriteAllText($"code-coverage-results.{fileExt}", output); + } + else + { + Console.WriteLine("Error: Unknown output type."); + return -2; // error + } - return 0; // success - } - } - catch (Exception ex) - { - Console.WriteLine($"Error: {ex.GetType()} - {ex.Message}"); - return -3; // unhandled error - } - }, - errs => -1); // invalid arguments + return 0; // success + } + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.GetType()} - {ex.Message}"); + return -3; // unhandled error + } + }, + _ => -1); // invalid arguments } private static CodeSummary ParseTestResults(string filename)