Skip to content

Commit

Permalink
Merge pull request #24 from Lombiq/issue/INFRA-135
Browse files Browse the repository at this point in the history
INFRA-135: Fixing PowerShell analyzer warning suppressions
  • Loading branch information
Piedone authored Jan 18, 2023
2 parents eff4343 + a7284bb commit 6d747a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Lombiq.Analyzers.PowerShell/Invoke-Analyzer.ps1
Original file line number Diff line number Diff line change
@@ -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.')]
Expand Down
7 changes: 6 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down

0 comments on commit 6d747a4

Please sign in to comment.