GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add some necessary contents for diagnostic suppressions. by t-lipingma · Pull Request #1694 · PowerShell/PSScriptAnalyzer

Conversation

@t-lipingma

@t-lipingma t-lipingma commented Jul 9, 2021 •
edited by rjmholt
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

PR Summary

Fixes #1691.

Output Suppressions to sarif result file.

  • Add a list of suppressions for each diagnostic.

  • Add -IncludeSuppressions parameter for output all violations including suppressed one.

  • Add Kind attribute in RuleSuppression.

  • Add test cases for those changes.

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .cs, .ps1 and .psm1 files have the correct copyright header
  • Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ghost

Deleted user (ghost) commented Jul 9, 2021 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@t-lipingma t-lipingma changed the title Suppressions-changes WIP:Suppressions-changes Jul 9, 2021
@t-lipingma t-lipingma changed the title WIP:Suppressions-changes WIP: suppressions-changes Jul 9, 2021
@t-lipingma

t-lipingma commented Jul 9, 2021

Copy link
Copy Markdown
Author

tests issue needs to solve before merge: #1695

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@t-lipingma
t-lipingma force-pushed the suppression-changes branch from 1e8aa16 to 2d5c96c Compare July 15, 2021 01:54
@rjmholt

Rob Holt (rjmholt) commented Jul 15, 2021

Copy link
Copy Markdown
Contributor

/azp run

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@azure-pipelines

azure-pipelines Bot commented Jul 15, 2021

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rjmholt
Rob Holt (rjmholt) reviewed Jul 15, 2021
View reviewed changes
Comment thread Engine/Commands/InvokeScriptAnalyzerCommand.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Engine/Generic/RuleSuppression.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Engine/Generic/SuppressedRecord.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@t-lipingma
add-suppressions
3139f05
@t-lipingma
t-lipingma force-pushed the suppression-changes branch from 2d5c96c to 3139f05 Compare July 16, 2021 08:26
@t-lipingma t-lipingma changed the title WIP: suppressions-changes Add some necessary contents for diagnostic suppressions. Jul 16, 2021
rjmholt
Rob Holt (rjmholt) reviewed Jul 16, 2021
View reviewed changes
Comment thread Engine/Generic/SuppressedRecord.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Engine/Generic/SuppressedRecord.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Engine/Helper.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Engine/Helper.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Engine/ScriptAnalyzer.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Engine/Commands/InvokeScriptAnalyzerCommand.cs Outdated
/// <summary>
/// ShowAll: Show the suppressed and non-suppressed message
/// </summary>
[Parameter(Mandatory = false)]

@rjmholt Rob Holt (rjmholt) Jul 16, 2021

Copy link
Copy Markdown
Contributor

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 isn't mutually exclusive with SuppressedOnly and probably should be. What should a user expect when both are provided?

Given that -SuppressedOnly already exists and we don't want to remove or otherwise break it, we probably can't move to an enum parameter like -SuppressionPreference <Exclude | Include | SuppressedOnly>.

An alternative might be to put each switch into its own parameter set, but that starts to get complicated. We should discuss this further.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rjmholt Rob Holt (rjmholt) Jul 16, 2021

Copy link
Copy Markdown
Contributor

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.

Suggested change
[Parameter(Mandatory = false)]
[Parameter]

Mandatory defaults to false

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JamesWTruher James Truher (JamesWTruher) Jul 16, 2021

Copy link
Copy Markdown
Contributor

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.

correct, if it's not mandatory, that should just be omitted. if SuppressedOnly should not be used with this, then parameter sets should be used (and it does get complicated). Although it doesn't look to complicated at the moment it would mean an additional 2 parameter sets.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@t-lipingma t-lipingma Jul 17, 2021

Copy link
Copy Markdown
Author

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 totally agree with you guys on that point.
If you decided to change the parameter set, let's discuss more details on the design, I'd like to help.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rjmholt Rob Holt (rjmholt) Jul 20, 2021

Copy link
Copy Markdown
Contributor

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.

From our offline conversation:

If the parameter set change is too complicated, can we check in the current solution firstly?

Yeah I think it's a good idea for us to separate out the suppression combining parts from the new parameter/feature. We can then discuss offline or over a call what the best way forward is.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@t-lipingma t-lipingma Jul 21, 2021

Copy link
Copy Markdown
Author

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.

To maintain PSSA's existing design, I think we can make '-SuppressedOnly' / '-IncludeSuppressions' exclusive in the short term. What do you think about it? Look forward to your reply.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@t-lipingma t-lipingma Jul 21, 2021

Copy link
Copy Markdown
Author

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.

Btw, ExcludeRule and IncludeRule should also be mutually exclusive.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rjmholt Rob Holt (rjmholt) Jul 21, 2021

Copy link
Copy Markdown
Contributor

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.

make '-SuppressedOnly' / '-IncludeSuppressions' exclusive

Yeah, they should be in different parameter sets.

Btw, ExcludeRule and IncludeRule should also be mutually exclusive.

No, those can be used together to include a non-default rule while excluding a default one.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@t-lipingma t-lipingma Jul 23, 2021

Copy link
Copy Markdown
Author

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.

To make -SuppressedOnly / -IncludeSuppressions exclusive.
I used the logic below:

 Function TestParamSet {
    [CmdletBinding(DefaultParameterSetName="File1")]
    Param
    (
	[Parameter(Position = 0,ParameterSetName = 'File1',Mandatory = true)]
        [Parameter(Position = 0,ParameterSetName = 'File2',Mandatory = true]
        [switch] $Path,
        
	[Parameter(Position = 0,ParameterSetName = 'ScriptDefinition1',Mandatory = true)]
        [Parameter(Position = 0,ParameterSetName = 'ScriptDefinition2',Mandatory = true)]
	[switch] $ScriptDefinition,
        
        
        [Parameter(ParameterSetName = 'File1', Mandatory = false)]
        [Parameter(ParameterSetName = 'ScriptDefinition1', Mandatory = false)]
        [switch] $SuppressedOnly,

        [Parameter(ParameterSetName = 'File2', Mandatory = true)]
        [Parameter(ParameterSetName = 'ScriptDefinition2', Mandatory = true)]
        [switch] $IncludeSuppressions

        [Parameter(Position = 0,ParameterSetName = 'File1',Mandatory = false)]
        [Parameter(Position = 0,ParameterSetName = 'File2',Mandatory = false]
        [switch] $Fix,
    )

    Process {
        #Do Nothing
    }
}

so it's to say:

1、Invoke-ScriptAnalyzer C:\build.ps1 --> ParameterSetName==DefaultParameterSetName.

2、Invoke-ScriptAnalyzer -Path C:\build.ps1 --> ParameterSetName==DefaultParameterSetName.

3、Invoke-ScriptAnalyzer -Path C:\build.ps1 -SuppressedOnly --> ParameterSetName=="File1".

4、Invoke-ScriptAnalyzer -Path C:\build.ps1 -IncludeSuppressions --> ParameterSetName=="File2".

5、Invoke-ScriptAnalyzer -ScriptDefinition $tmp --> ParameterSetName=="ScriptDefinition1".

6、Invoke-ScriptAnalyzer -ScriptDefinition $tmp -SuppressedOnly --> ParameterSetName=="ScriptDefinition1"

7、Invoke-ScriptAnalyzer -ScriptDefinition $tmp -IncludeSuppressions -->ParameterSetName=="ScriptDefinition2"

LMK if you have any suggestions, Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Engine/Generic/RuleSuppression.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Tests/Engine/RuleSuppression.tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

JamesWTruher
James Truher (JamesWTruher) reviewed Jul 16, 2021
View reviewed changes
Comment thread Engine/Commands/InvokeScriptAnalyzerCommand.cs Outdated
/// <summary>
/// ShowAll: Show the suppressed and non-suppressed message
/// </summary>
[Parameter(Mandatory = false)]

@JamesWTruher James Truher (JamesWTruher) Jul 16, 2021

Copy link
Copy Markdown
Contributor

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.

correct, if it's not mandatory, that should just be omitted. if SuppressedOnly should not be used with this, then parameter sets should be used (and it does get complicated). Although it doesn't look to complicated at the moment it would mean an additional 2 parameter sets.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Tests/Engine/RuleSuppression.tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Engine/ScriptAnalyzer.types.ps1xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Engine/ScriptAnalyzer.types.ps1xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JamesWTruher
James Truher (JamesWTruher) requested a review from Christoph Bergmeister (bergmeister) July 16, 2021 19:56
@JamesWTruher

James Truher (JamesWTruher) commented Jul 16, 2021

Copy link
Copy Markdown
Contributor

Christoph Bergmeister (@bergmeister) could you also please take a look at this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rjmholt Rob Holt (rjmholt) mentioned this pull request Jul 21, 2021
Combine multiple suppressions applied to the same diagnostic #1699
Merged
6 tasks done
@rjmholt

Rob Holt (rjmholt) commented Jul 21, 2021

Copy link
Copy Markdown
Contributor

t-lipingma I've implemented the suppression combination part of this work in #1699.

t-lipingma and bergmeister reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bergmeister
Christoph Bergmeister (bergmeister) reviewed Jul 22, 2021
View reviewed changes

@bergmeister Christoph Bergmeister (bergmeister) left a comment

Copy link
Copy Markdown
Collaborator

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.

Interesting idea. I wonder if it would also be useful to the user if the DiagnosticRecord gets an additional property whether it would've been suppressed so that the user does not need to run pssa twice and do logic on two sets of records.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rjmholt reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@t-lipingma
parametersets
791bd0c
@t-lipingma t-lipingma closed this Jul 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bergmeister Christoph Bergmeister (bergmeister) bergmeister left review comments
+2 more reviewers
@rjmholt Rob Holt (rjmholt) rjmholt left review comments
@JamesWTruher James Truher (JamesWTruher) JamesWTruher left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Add a list of suppressions for each dianostic

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@t-lipingma @rjmholt @JamesWTruher @bergmeister
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.