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

PSScriptAnalyzer doesn't seem to be using the SuppressMessageAttribute ctor fields as intended. #276

Open
rkeithhill opened this issue Jul 15, 2015 · 2 comments

Comments

@rkeithhill
Copy link
Contributor

So here is an example of how PSScriptAnalyzer is using this attribute to target a parameter:

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideDefaultParameterValue", "b")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideDefaultParameterValue", "a")]
Param([string]$a, [int]$b)

But the intent of the first two parameters of the SuppressMessageAttribute constructor are to uniquely identify the suppressed rule, and to apply to a parameter would use the MessageId property e.g.:

[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "isChecked")]
[SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "fileIdentifier")]
static void FileNode(string name, bool isChecked)

So I would expect that every PowerShell suppression of a built-in rule would start like this:

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.PowerShell", "PSAvoidUsingCmdletAliases")]

This identifies the rule as a built-in rule. I could imagine custom rules would use their module/assembly name in the first field (category).

Suppression of a parameter should look like:

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.PowerShell", "PSProvideDefaultParameterValue", MessageId="b")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.PowerShell", "PSProvideDefaultParameterValue", MessageId="a")]
Param([string]$a, [int]$b)

Note that MessageId is the field that is supposed to be used if Scope/Target aren't sufficiently precise.

@rkeithhill
Copy link
Contributor Author

Another option for the category parameter for built-in rules could be:

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSScriptAnalyzer.PS", "PSProvideDefaultParameterValue", MessageId="a")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSScriptAnalyzer.PSDSC", "PSDSCDscTestsPresent")]

@raghushantha
Copy link
Member

Keith. Thanks for your input.

This is a feature request and we will add to the backlog items

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

No branches or pull requests

4 participants