Skip to content

Add some necessary contents for diagnostic suppressions. #1694

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

Closed
wants to merge 2 commits into from

Conversation

t-lipingma
Copy link

@t-lipingma t-lipingma commented Jul 9, 2021

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

@ghost
Copy link

ghost commented Jul 9, 2021

CLA assistant check
All CLA requirements met.

@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
Copy link
Author

tests issue needs to solve before merge: #1695

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

rjmholt commented Jul 15, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@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
/// <summary>
/// ShowAll: Show the suppressed and non-suppressed message
/// </summary>
[Parameter(Mandatory = false)]
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Author

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!

/// <summary>
/// ShowAll: Show the suppressed and non-suppressed message
/// </summary>
[Parameter(Mandatory = false)]
Copy link
Contributor

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.

@JamesWTruher JamesWTruher requested a review from bergmeister July 16, 2021 19:56
@JamesWTruher
Copy link
Contributor

@bergmeister could you also please take a look at this?

@rjmholt
Copy link
Contributor

rjmholt commented Jul 21, 2021

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

Copy link
Collaborator

@bergmeister bergmeister left a 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.

@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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a list of suppressions for each dianostic
4 participants