Skip to content

Invoke-ScriptAnalyzer: Include parse errors in reported error count #2069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions Engine/Commands/InvokeScriptAnalyzerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,36 +416,35 @@ protected override void EndProcessing()
ScriptAnalyzer.Instance.CleanUp();
base.EndProcessing();

var infoCount = diagnosticCounts[DiagnosticSeverity.Information];
var warningCount = diagnosticCounts[DiagnosticSeverity.Warning];
var errorCount = diagnosticCounts[DiagnosticSeverity.Error];
var parseErrorCount = diagnosticCounts[DiagnosticSeverity.ParseError];
var diagnosticCount = diagnosticCounts.Values.Sum();

if (ReportSummary.IsPresent)
{
var numberOfRuleViolations = infoCount + warningCount + errorCount;
if (numberOfRuleViolations == 0)
if (diagnosticCount == 0)
{
Host.UI.WriteLine("0 rule violations found.");
}
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);
}
var infoCount = diagnosticCounts[DiagnosticSeverity.Information];
var warningCount = diagnosticCounts[DiagnosticSeverity.Warning];
var errorCount = diagnosticCounts[DiagnosticSeverity.Error] + diagnosticCounts[DiagnosticSeverity.ParseError];
var severeDiagnosticCount = diagnosticCount - infoCount;

var colorPropertyPrefix = severeDiagnosticCount == 0 ? "Warning" : "Error";
var pluralS = diagnosticCount > 1 ? "s" : string.Empty;
ConsoleHostHelper.DisplayMessageUsingSystemProperties(
Host, colorPropertyPrefix + "ForegroundColor", colorPropertyPrefix + "BackgroundColor",
$"{diagnosticCount} rule violation{pluralS} found. Severity distribution: " +
$"{DiagnosticSeverity.Error} = {errorCount}, " +
$"{DiagnosticSeverity.Warning} = {warningCount}, " +
$"{DiagnosticSeverity.Information} = {infoCount}");
}
}

if (EnableExit)
{
this.Host.SetShouldExit(diagnosticCounts.Values.Sum());
this.Host.SetShouldExit(diagnosticCount);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Engine/InvokeScriptAnalyzer.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ Describe "-ReportSummary switch" {
$pwshExe = 'powershell'
}

$reportSummaryFor1Warning = '*1 rule violation found. Severity distribution: Error = 0, Warning = 1, Information = 0*'
$reportSummaryFor1Warning = '*1 rule violation found. Severity distribution: Error = 0, Warning = 1, Information = 0*'
}

It "prints the correct report summary using the -NoReportSummary switch" {
Expand Down