From bfa22abd91feecbaa6041079f0f28187907c5185 Mon Sep 17 00:00:00 2001 From: Benedek Farkas Date: Wed, 18 Jan 2023 16:51:05 +0100 Subject: [PATCH 1/2] Adding more details to Readme on suppressing analyzer warnings --- Readme.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index e56a668b..87767b50 100644 --- a/Readme.md +++ b/Readme.md @@ -76,7 +76,12 @@ Live analysis is outside of the scope of this project, however you can use the V ### Suppressing PSScriptAnalyzer rules -Occasionally there is good reason to ignore an analyzer warning. In this case add the `[Diagnostics.CodeAnalysis.SuppressMessage('Rule Code', '', Justification = 'Explain reason.')]` attribute to the cmdlet's `param()`. For more information, see the module's [documentation](https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/using-scriptanalyzer?view=ps-modules#suppressing-rules). +Occasionally there is good reason to ignore an analyzer warning. In this case add the `[Diagnostics.CodeAnalysis.SuppressMessage('PSCategoryId', 'ParameterName', Justification = 'Explain why.')]` attribute to the cmdlet's `param()` block. The first two parameters are mandatory: + +1. `PSCategoryId` is an example for the Id of the analyzer rule and it usually starts with _PS_. +2. `ParameterName` is an example for the name of the parameter (notice that it doesn't start with `$`). Leave it empty if the suppression is not specific to a parameter. + +For more information, see the module's [documentation](https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/using-scriptanalyzer?view=ps-modules#suppressing-rules). Suppressing a specific line or range (like `#pragma warning disable` in C#) is not currently supported. See [the associated PSScriptAnalyzer issue](https://github.com/PowerShell/PSScriptAnalyzer/issues/849). From a7284bb5261abc344e113dcb19711821d1b8b99e Mon Sep 17 00:00:00 2001 From: Benedek Farkas Date: Wed, 18 Jan 2023 16:59:38 +0100 Subject: [PATCH 2/2] "SuppressMessage" instead of "SuppressMessageAttribute" --- Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 index 461373e9..91b65bda 100644 --- a/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 +++ b/Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1 @@ -1,12 +1,12 @@ -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( +[Diagnostics.CodeAnalysis.SuppressMessage( 'PSReviewUnusedParameter', 'ForGitHubActions', Justification = 'False positive due to https://github.com/PowerShell/PSScriptAnalyzer/issues/1472.')] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( +[Diagnostics.CodeAnalysis.SuppressMessage( 'PSReviewUnusedParameter', 'ForMsBuild', Justification = 'False positive due to https://github.com/PowerShell/PSScriptAnalyzer/issues/1472.')] -[Diagnostics.CodeAnalysis.SuppressMessageAttribute( +[Diagnostics.CodeAnalysis.SuppressMessage( 'PSReviewUnusedParameter', 'IncludeTestSolutions', Justification = 'False positive due to https://github.com/PowerShell/PSScriptAnalyzer/issues/1472.')]