PSReviewUnusedParameter has false positive when using $MyInvocation.BoundParameters
See original GitHub issueSteps to reproduce
There may be some rare cases where we would be using ParameterSetName instead of ParameterName, for example
$sb = {
function Test-PSReviewUnusedParameter {
<#
#>
[CmdletBinding()]
Param(
[Parameter(ParameterSetName = 'Foo')]
[switch]
$FooBar
)
try{
if ($PSCmdlet.ParameterSetName -eq 'Foo') {
# I am doing something
}
} catch {
throw
}
}
}
# Invoke-ScriptAnalyzer -ScriptDefinition [scriptblock]$sb
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSReviewUnusedParameter Warning 9 The parameter 'FooBar' has been declared but not used.
Expected behavior
I expect this to be not flagged
Actual behavior
Flags it as violation
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.18362.752
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.18362.752
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (11 by maintainers)
Top Results From Across the Web
PSFramework.psm1 1.3.140-preview2
Once that session has been established, the session object can be used with this command and will be used for command invocation. .PARAMETER...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have the changes ready, waiting for my firm to approve my OSS contribution.
Cool, Thanks. I will submit a PR. Thanks @bergmeister