Skip to content

Commit 0fecc08

Browse files
authored
Do not print summary repeatedly for each logger (#2058)
1 parent 3a91195 commit 0fecc08

File tree

1 file changed

+43
-42
lines changed

1 file changed

+43
-42
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,7 @@ protected override void StopProcessing()
431431

432432
private void ProcessInput()
433433
{
434-
var diagnosticRecords = RunAnalysis();
435-
WriteToOutput(diagnosticRecords);
436-
totalDiagnosticCount += diagnosticRecords.Count;
434+
WriteToOutput(RunAnalysis());
437435
}
438436

439437
private List<DiagnosticRecord> RunAnalysis()
@@ -461,56 +459,59 @@ private List<DiagnosticRecord> RunAnalysis()
461459
return diagnostics;
462460
}
463461

464-
private void WriteToOutput(List<DiagnosticRecord> diagnosticRecords)
462+
private void WriteToOutput(IEnumerable<DiagnosticRecord> diagnosticRecords)
465463
{
466-
foreach (ILogger logger in ScriptAnalyzer.Instance.Loggers)
467-
{
468-
var errorCount = 0;
469-
var warningCount = 0;
470-
var infoCount = 0;
471-
var parseErrorCount = 0;
464+
var errorCount = 0;
465+
var warningCount = 0;
466+
var infoCount = 0;
467+
var parseErrorCount = 0;
472468

473-
foreach (DiagnosticRecord diagnostic in diagnosticRecords)
469+
foreach (DiagnosticRecord diagnostic in diagnosticRecords)
470+
{
471+
foreach (ILogger logger in ScriptAnalyzer.Instance.Loggers)
474472
{
475473
logger.LogObject(diagnostic, this);
476-
switch (diagnostic.Severity)
477-
{
478-
case DiagnosticSeverity.Information:
479-
infoCount++;
480-
break;
481-
case DiagnosticSeverity.Warning:
482-
warningCount++;
483-
break;
484-
case DiagnosticSeverity.Error:
485-
errorCount++;
486-
break;
487-
case DiagnosticSeverity.ParseError:
488-
parseErrorCount++;
489-
break;
490-
default:
491-
throw new ArgumentOutOfRangeException(nameof(diagnostic.Severity), $"Severity '{diagnostic.Severity}' is unknown");
492-
}
493474
}
494475

495-
if (ReportSummary.IsPresent)
476+
totalDiagnosticCount++;
477+
478+
switch (diagnostic.Severity)
479+
{
480+
case DiagnosticSeverity.Information:
481+
infoCount++;
482+
break;
483+
case DiagnosticSeverity.Warning:
484+
warningCount++;
485+
break;
486+
case DiagnosticSeverity.Error:
487+
errorCount++;
488+
break;
489+
case DiagnosticSeverity.ParseError:
490+
parseErrorCount++;
491+
break;
492+
default:
493+
throw new ArgumentOutOfRangeException(nameof(diagnostic.Severity), $"Severity '{diagnostic.Severity}' is unknown");
494+
}
495+
}
496+
497+
if (ReportSummary.IsPresent)
498+
{
499+
var numberOfRuleViolations = infoCount + warningCount + errorCount;
500+
if (numberOfRuleViolations == 0)
501+
{
502+
Host.UI.WriteLine("0 rule violations found.");
503+
}
504+
else
496505
{
497-
var numberOfRuleViolations = infoCount + warningCount + errorCount;
498-
if (numberOfRuleViolations == 0)
506+
var pluralS = numberOfRuleViolations > 1 ? "s" : string.Empty;
507+
var message = $"{numberOfRuleViolations} rule violation{pluralS} found. Severity distribution: {DiagnosticSeverity.Error} = {errorCount}, {DiagnosticSeverity.Warning} = {warningCount}, {DiagnosticSeverity.Information} = {infoCount}";
508+
if (warningCount + errorCount == 0)
499509
{
500-
Host.UI.WriteLine("0 rule violations found.");
510+
ConsoleHostHelper.DisplayMessageUsingSystemProperties(Host, "WarningForegroundColor", "WarningBackgroundColor", message);
501511
}
502512
else
503513
{
504-
var pluralS = numberOfRuleViolations > 1 ? "s" : string.Empty;
505-
var message = $"{numberOfRuleViolations} rule violation{pluralS} found. Severity distribution: {DiagnosticSeverity.Error} = {errorCount}, {DiagnosticSeverity.Warning} = {warningCount}, {DiagnosticSeverity.Information} = {infoCount}";
506-
if (warningCount + errorCount == 0)
507-
{
508-
ConsoleHostHelper.DisplayMessageUsingSystemProperties(Host, "WarningForegroundColor", "WarningBackgroundColor", message);
509-
}
510-
else
511-
{
512-
ConsoleHostHelper.DisplayMessageUsingSystemProperties(Host, "ErrorForegroundColor", "ErrorBackgroundColor", message);
513-
}
514+
ConsoleHostHelper.DisplayMessageUsingSystemProperties(Host, "ErrorForegroundColor", "ErrorBackgroundColor", message);
514515
}
515516
}
516517
}

0 commit comments

Comments
 (0)