-
Notifications
You must be signed in to change notification settings - Fork 378
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
Implement -IncludeSuppressions parameter #1701
Implement -IncludeSuppressions parameter #1701
Conversation
This comment has been minimized.
This comment has been minimized.
I finally worked this out. We have a bizarre test that overrides |
This comment has been minimized.
This comment has been minimized.
WriteToOutput(diagnosticsList); | ||
if (fix) | ||
{ | ||
ShouldProcess(path, $"Analyzing and fixing path with Recurse={this.recurse}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a bug with the original code? If I read this correctly we will take the action no matter what, but ShouldProcess
is supposed to notify the user and not take the action in the case of -WhatIf
. this code will fix the script even with -WhatIf
. I get that it's not as big a deal for just the diagnosis part, but the fix part seems wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I saw this and had the same thought. Definitely something we should review. If @bergmeister agrees, I can open an issue to track it so we can fix it beyond this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This goes back to my very first PR in PSSA, where I added the -Fix
switch and since this is an action that changes state, I implemented ShouldProcess
for it and declared that on the cmdlet. Since the -Fix
parameter is only on the -File
parameter set, I did not implement it for the -ScriptDefinition
parameter set. Original commit is here: bfa1c54
Therefore I still think it's not really important here, very rarely does one run PSSA where the command would take ages and performing a dry-run would save time. Still happy to have a tracking issue
@@ -24,6 +24,7 @@ public class SuppressedRecord : DiagnosticRecord | |||
public SuppressedRecord(DiagnosticRecord record, IReadOnlyList<RuleSuppression> suppressions) | |||
{ | |||
Suppression = new ReadOnlyCollection<RuleSuppression>(new List<RuleSuppression>(suppressions)); | |||
IsSuppressed = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this ever be called with a suppression list count of zero? In that case IsSuppressed really true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good question. I think the mere wrapping in the SuppressedRecord
object classes the diagnostic as suppressed, but I agree that this opens up the possibility of an invalid object, which I dislike... I'm not sure I see a way around this without changing a few things around though, and I'm not sure that's worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good but not sure whether doubling the parameter sets is the right way. This can make the experience more confusing for users and makes maintenance more complicated as well. How about an Enum parameter instead that has a default?
Some good improvements to tests that made some assumptions :-)
So I would prefer an enum parameter, but that would be a breaking change; invocations that previously use In order to keep |
Hmm, didn't realize Having said that, this topic is opinionated and I am sure the other side will argue for param sets with its early validation before actually running the command. Therefore I suggest we let a 3rd person like @JamesWTruher decide on this matter. I am happy with the rest of the PR. |
@rjmholt @bergmeister i'm generally in favor of adding parameter sets where they make sense and don't over complicate things. In this case we're going from 2 to only 4 so i don't believe it's a higher cognitive load. The benefit with parameter sets is that we can determine behavior via inspection rather than runtime, so tools like vscode provide a better experience. |
c970e73
to
02ccd84
Compare
@bergmeister @JamesWTruher need an approval to merge 🙂 |
PR Summary
Implements the
-IncludeSuppressions
parameter, allowing a singleInvoke-ScriptAnalyzer
invocation to emit all diagnostics including suppressed ones, decorating the suppressed ones accordingly.Also adds an
IsSuppressed
property on diagnostics./cc @t-lipingma
PR Checklist
.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
to the beginning of the title and remove the prefix when the PR is ready.