Skip to content

Commit

Permalink
Do not print summary repeatedly for each logger (#2058)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatejKafka authored Feb 20, 2025
1 parent 3a91195 commit 0fecc08
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions Engine/Commands/InvokeScriptAnalyzerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,7 @@ protected override void StopProcessing()

private void ProcessInput()
{
var diagnosticRecords = RunAnalysis();
WriteToOutput(diagnosticRecords);
totalDiagnosticCount += diagnosticRecords.Count;
WriteToOutput(RunAnalysis());
}

private List<DiagnosticRecord> RunAnalysis()
Expand Down Expand Up @@ -461,56 +459,59 @@ private List<DiagnosticRecord> RunAnalysis()
return diagnostics;
}

private void WriteToOutput(List<DiagnosticRecord> diagnosticRecords)
private void WriteToOutput(IEnumerable<DiagnosticRecord> diagnosticRecords)
{
foreach (ILogger logger in ScriptAnalyzer.Instance.Loggers)
{
var errorCount = 0;
var warningCount = 0;
var infoCount = 0;
var parseErrorCount = 0;
var errorCount = 0;
var warningCount = 0;
var infoCount = 0;
var parseErrorCount = 0;

foreach (DiagnosticRecord diagnostic in diagnosticRecords)
foreach (DiagnosticRecord diagnostic in diagnosticRecords)
{
foreach (ILogger logger in ScriptAnalyzer.Instance.Loggers)
{
logger.LogObject(diagnostic, this);
switch (diagnostic.Severity)
{
case DiagnosticSeverity.Information:
infoCount++;
break;
case DiagnosticSeverity.Warning:
warningCount++;
break;
case DiagnosticSeverity.Error:
errorCount++;
break;
case DiagnosticSeverity.ParseError:
parseErrorCount++;
break;
default:
throw new ArgumentOutOfRangeException(nameof(diagnostic.Severity), $"Severity '{diagnostic.Severity}' is unknown");
}
}

if (ReportSummary.IsPresent)
totalDiagnosticCount++;

switch (diagnostic.Severity)
{
case DiagnosticSeverity.Information:
infoCount++;
break;
case DiagnosticSeverity.Warning:
warningCount++;
break;
case DiagnosticSeverity.Error:
errorCount++;
break;
case DiagnosticSeverity.ParseError:
parseErrorCount++;
break;
default:
throw new ArgumentOutOfRangeException(nameof(diagnostic.Severity), $"Severity '{diagnostic.Severity}' is unknown");
}
}

if (ReportSummary.IsPresent)
{
var numberOfRuleViolations = infoCount + warningCount + errorCount;
if (numberOfRuleViolations == 0)
{
Host.UI.WriteLine("0 rule violations found.");
}
else
{
var numberOfRuleViolations = infoCount + warningCount + errorCount;
if (numberOfRuleViolations == 0)
var pluralS = numberOfRuleViolations > 1 ? "s" : string.Empty;
var message = $"{numberOfRuleViolations} rule violation{pluralS} found. Severity distribution: {DiagnosticSeverity.Error} = {errorCount}, {DiagnosticSeverity.Warning} = {warningCount}, {DiagnosticSeverity.Information} = {infoCount}";
if (warningCount + errorCount == 0)
{
Host.UI.WriteLine("0 rule violations found.");
ConsoleHostHelper.DisplayMessageUsingSystemProperties(Host, "WarningForegroundColor", "WarningBackgroundColor", message);
}
else
{
var pluralS = numberOfRuleViolations > 1 ? "s" : string.Empty;
var message = $"{numberOfRuleViolations} rule violation{pluralS} found. Severity distribution: {DiagnosticSeverity.Error} = {errorCount}, {DiagnosticSeverity.Warning} = {warningCount}, {DiagnosticSeverity.Information} = {infoCount}";
if (warningCount + errorCount == 0)
{
ConsoleHostHelper.DisplayMessageUsingSystemProperties(Host, "WarningForegroundColor", "WarningBackgroundColor", message);
}
else
{
ConsoleHostHelper.DisplayMessageUsingSystemProperties(Host, "ErrorForegroundColor", "ErrorBackgroundColor", message);
}
ConsoleHostHelper.DisplayMessageUsingSystemProperties(Host, "ErrorForegroundColor", "ErrorBackgroundColor", message);
}
}
}
Expand Down

0 comments on commit 0fecc08

Please sign in to comment.