PowerShell / PowerShell/PSScriptAnalyzer
`SuppressMessageAttribute` not working for ScriptBlock params
Open
Nobody has claimed this yet.
Area - Rule Sets
Issue - Enhancement
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
Before submitting a bug report:
- Make sure you are able to repro it on the latest released version
- Perform a quick search for existing issues to check if this bug has already been reported
Steps to reproduce
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'wordToComplete', Justification = 'Reason for suppressing')]
param(
$wordToComplete,
$commandAst,
$cursorPosition)
dotnet complete --position $cursorPosition "$commandAst" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
Expected behavior
Rule `PSReviewUnusedParameter` doesn't trigger for parameter `$wordToComplete`.
Actual behavior
Rule `PSReviewUnusedParameter` triggers for parameter `$wordToComplete`.
If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 7.3.0
PSEdition Core
GitCommitId 7.3.0
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
Using built-in version of VSCode Powershell extension (v2022.10.0)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the PowerShell example with the PSReviewUnusedParameter rule and confirm that the suppression attribute is ignored for $wordToComplete. Trace the analyzer entry point for ScriptBlock parameters and inspect its existing tests, if present. Done means the rule no longer reports that parameter while preserving the current behavior for unsuppressed parameters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100