PSScriptAnalyzer icon indicating copy to clipboard operation
PSScriptAnalyzer copied to clipboard

Diagnostics.CodeAnalysis.SuppressMessageAttribute should take an array of category names

Open Jaykul opened this issue 9 years ago • 2 comments

The attribute needs to take an array of categories. I shouldn't have to add a new instance of the attribute for each category I want to suppress.

Having to write a separate line for every rule I need to suppress is extremely frustrating and verbose. Take for example this 2 line internal function:

function New-PSCredential {
   [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword")] # It's encoded, leave me alone
   [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingUserNameAndPasswordParams")] # That's the whole point of this function
   [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideCommentHelp")] # No point for a constructor function with parameters this simple
   [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSProvideDefaultParameterValue")] # No point for internal functions
   [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseOutputTypeCorrectly")] # No point for internal functions
   param([string]$UserName, [string]$EncodedPassword)
   New-Object PSCredential $UserName, (ConvertTo-SecureString $EncodedPassword)
}

Seriously?

Jaykul avatar Mar 07 '16 18:03 Jaykul

Thanks for the feedback.

Originally, we modeled this after System.Diagnostics.CodeAnalysis.SuppressMessage in .net.

But, since we control the implementation we can definitely optimize the experience.

Marking this as a new feature

raghushantha avatar Mar 07 '16 19:03 raghushantha

It would be really cool if the parameter name could also be an array to suppress the same category for multiple parameters in one go. Maybe not at the same time as defining an array for the category, as that might have unintentional consequences.

BenedekFarkas avatar Feb 15 '24 10:02 BenedekFarkas