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

Add a list of suppressions for each dianostic #1691

Closed
t-lipingma opened this issue Jun 30, 2021 · 1 comment · Fixed by #1699
Closed

Add a list of suppressions for each dianostic #1691

t-lipingma opened this issue Jun 30, 2021 · 1 comment · Fixed by #1699

Comments

@t-lipingma
Copy link

Steps to reproduce

Now I suppressed one rule twice in “function start-bar”.

  1. PowerShell script: build.ps1
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope='Function', Target='start-ba[rz]',Justification="aa")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Scope='Function', Target='start-bar',Justification="bb")]
param()
function start-foo {
    write-host "start-foo"
}

function start-bar {
    write-host "start-bar"
}

function start-bam {
    write-host "start-bam"
}
  1. if you already import the module, may skip this step.
Import-Module .\out\PSScriptAnalyzer\1.20.0\PSScriptAnalyzer.psd1
  1. run PSScriptAnalyzer to analyze build.ps1. If not add -SuppressedOnly parameter, it only outputs non-suppressed results. So I add -SuppressedOnly parameter to see suppressed results.
Invoke-ScriptAnalyzer D:\build.ps1 -Recurse -SuppressedOnly

Expected behavior

RuleName                            Severity     ScriptName Line  Justification              
--------                            --------     ---------- ----  -------------                                      
PSAvoidUsingWriteHost               Warning      build.ps1  9     aa;bb   

If one rule suppressed twice in the same line, it needs to have a list of suppressions for the diagnostic.

Actual behavior

RuleName                            Severity     ScriptName Line  Justification              
--------                            --------     ---------- ----  -------------                                      
PSAvoidUsingWriteHost               Warning      build.ps1  9     aa                                         
PSAvoidUsingWriteHost               Warning      build.ps1  9     bb                             

The results seem like the existing implementation generates an output for each suppression, rather than each diagnostic.
So it's maybe better to have a list of suppressions for each diagnostic.

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1023
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1023
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
@rjmholt
Copy link
Contributor

rjmholt commented Jul 6, 2021

Although this would be a breaking change, I think the proposed change is relatively minor and makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment