GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PSScriptAnalyzer doesn't seem to be using the SuppressMessageAttribute ctor fields as intended. · Issue #276 · PowerShell/PSScriptAnalyzer

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

New issue
Copy link
New issue
Copy link
Open
Open
PSScriptAnalyzer doesn't seem to be using the SuppressMessageAttribute ctor fields as intended.#276
Copy link
Labels
Issue - Enhancement

Description

@rkeithhill
Keith Hill (rkeithhill)
opened on Jul 15, 2015
Issue body actions

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.

Activity

  1. rkeithhill commented on Jul 15, 2015

    @rkeithhill
    Keith Hill (rkeithhill)
    on Jul 15, 2015
    ContributorAuthor
    More actions

    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")]
  2. raghushantha commented on Jul 20, 2015

    @raghushantha
    Raghu Shantha (raghushantha)
    on Jul 20, 2015
    Member
    More actions

    Keith. Thanks for your input.

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

  3. Raghu Shantha (raghushantha)
    added
    New Feature
    on Jul 20, 2015
  4. Raghu Shantha (raghushantha)
    assigned
    Quoc Truong (quoctruong)
    on Jul 20, 2015
  5. Kapil Borle (kapilmb)
    added
    Issue - Enhancement
    and removed
    New Feature
    on Oct 26, 2016
  6. Kapil Borle (kapilmb)
    unassigned
    Quoc Truong (quoctruong)
    on Oct 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue - Enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.