Skip to content

RuleSuppressionId is not being honored for custom rule suppression #1686

Open
@jegannathanmaniganadan

Description

@jegannathanmaniganadan

Steps to reproduce

I have a bunch of custom rules written in PowerShell. For some of the rules I populate RuleSuppressionId in the diagnostic record, so that I can use that for rule suppression, but it is not working. For example, I have this violation returned for my custom rule, which I want to suppress across my psm1 file on a specific functions.

Line                 : 2107
Column               : 13
Message              : You should not use Get-FooBar,....
Extent               :  <some extent>
RuleName             : ScriptName\Measure-PSAvoidFooBarCommand
Severity             : Warning
ScriptName           : FooBar.psm1
ScriptPath           : C:\..\FooBar.psm1
RuleSuppressionID    : Get-FooBar
SuggestedCorrections : {Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent

And I have this line suppression defined at the beginning of the psm1 file,

[SuppressMessageAttribute('ScriptName\Measure-PSAvoidFooBarCommand', CheckId = 'Get-FooBar', Scope = 'Function', Target = 'Get-SomeFunction*')]
param()

Expected behavior

It should suppress the violation but it does not.

Actual behavior

It suppress all the violations for the given rule without checking the RuleSuppressionId.

if I tweak the suppression to below, I get an error

```powershell
[SuppressMessageAttribute('ScriptName\Measure-PSAvoidFooBarCommand', 'Get-FooBar', Scope = 'Function', Target = 'Get-SomeFunction*')]
param()
Suppression Message Attribute error at line 12 in FooBar.psm1 : Cannot find any DiagnosticRecord with the Rule Suppression ID Get-FooBar....

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.18362.1593
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.1593
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions