Skip to content
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

Invoke-ScriptAnalyzer: Print summary only once per invocation #2063

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MatejKafka
Copy link
Contributor

PR Summary

Similarly to the previous -EnableExit PR, this PR moves the summary printed when -ReportSummary is passed to EndProcessing, so that it's only printed once, instead of once for every value from the pipeline.

Imo, users are likely to be interested in the summary from all of the piped files, not for each file separately. Since the message is printed to the host (so the caller has no easy way to capture it), I don't believe moving it to be a breaking change.

PR Checklist

@andyleejordan andyleejordan force-pushed the single-summary-pipeline branch from ed43569 to cc57fa5 Compare February 25, 2025 00:16
Copy link
Member

@andyleejordan andyleejordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good refactor to me, thanks! Gotta love dictionaries.

private int totalDiagnosticCount = 0;
// initialize to zero for all severity enum values
private Dictionary<DiagnosticSeverity, int> diagnosticCounts =
Enum.GetValues<DiagnosticSeverity>().ToDictionary(s => s, _ => 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh it looks like this doesn't work in net462:

error CS0308: The non-generic method 'Enum.GetValues(Type)' cannot be used with type arguments 

so annoying...but based on my read of https://learn.microsoft.com/en-us/dotnet/api/system.enum.getvalues?view=net-9.0 I think you could do this with:

Enum.GetValues(DiagnosticSeverity).ToDictionary(s => (DiagnosticSeverity)s, _ => 0);

and that should work in all versions. Instead of the lovely builtin that just gets the strings for us, gotta get the enum values (which is just gonna be ints 0-3 I think) and then cast them back to the name...

scratch that I think you can just use Enum.GetNames(DiagnosticSeverity) per https://learn.microsoft.com/en-us/dotnet/api/system.enum.getnames?view=netframework-4.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants