You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check it with the default rules in PSScriptAnalyzer:
Invoke-ScriptAnalyzer-Path .\Get-Thing.ps1
RuleName Severity ScriptName Line Message
-------------------------------------
PSReviewUnusedParameter Warning Get-Thing.ps19 The parameter 'ParamSet2' has been declared but not used.
PSReviewUnusedParameter Warning Get-Thing.ps113 The parameter 'ParamSet3' has been declared but not used.
Is it objectively better to rewrite the function? Something like:
This is what I've been doing for the functions that have been caught with this error.
Expected behavior
I would expect the rule not to be triggered on this script.
Actual behavior
RuleName Severity ScriptName Line Message
-------- -------- ---------- ---- -------
PSReviewUnusedParameter Warning Get-Thing.ps1 9 The parameter 'ParamSet2' has been declared but not used.
PSReviewUnusedParameter Warning Get-Thing.ps1 13 The parameter 'ParamSet3' has been declared but not used.
Environment data
>$PSVersionTable
Name Value
---------
PSVersion 7.0.2
PSEdition Core
GitCommitId 7.0.2
OS Microsoft Windows 10.0.18362
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() }
1.19.0
The text was updated successfully, but these errors were encountered:
This sounds like a deja-vu of the original issue description in #1505
A parameter set can consist of one or more parameters. It's fine to use switch ($PSCmdlet.ParameterSetName) if it helps you to structure your code easier but the rule is still right that you do not use the actual parameter. If you use the parameters implicitly via $PSBoundParameters, then the rule won't fire and PR #1520 recently also added $MyInvocation.BoundParameters and $PSCmdlet.MyInvocation.BoundParameters to the exclusion list but that PR hasn't been released yet.
Also: The rule is not supposed to be an absolute but rather a heuristic. If you can justify your special use-case then that is what rule suppression is for.
Steps to reproduce
Check it with the default rules in PSScriptAnalyzer:
Is it objectively better to rewrite the function? Something like:
This is what I've been doing for the functions that have been caught with this error.
Expected behavior
I would expect the rule not to be triggered on this script.
Actual behavior
Environment data
The text was updated successfully, but these errors were encountered: