PowerShell / PowerShell/PSScriptAnalyzer

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

Open
#276 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue - Enhancement
Dominant language
C#
Stars
2.2k
Forks
414
Avg merge
13h 1m
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the PSScriptAnalyzer code that interprets SuppressMessageAttribute and tracing how its constructor arguments and MessageId are handled. Compare parameter-targeted suppressions with the attribute semantics shown in the issue; done means built-in rule suppressions use the category and rule fields, while parameter-specific targets use MessageId.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.