-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PSReviewUnusedParameter does not look in scriptblocks #1643
Comments
This is a tricky one, related to #1641. In your particular example, that parameter is indeed unused. The scriptblock referencing a variable of the same name is not invoked within the scope of that parameter. Instead, the scriptblock will be passed out of the function for later invocation when dynamic scope will mean it will pick up a different value of However, in this scenario: param($param)
& {
"Hello $param"
}
However a scenario like that is unusual. Much more common is something like: param($Value,, $Weight)
$Value | ForEach-Object { $sum = 0 } { $sum += $_ * $Weight } { $sum } However, solving this is non-trivial because we (1) must build a list of cmdlets that implicitly invoke their arguments within the current scope and (2) must work out special rules for all of them including a good way of working out how their parameters are bound. For example compare: param($X)
Invoke-Command { "Hello $X" } with: param($X)
Invoke-Command -ComputerName "MyOtherComputer" { "Hello $X" } Same command, but the scriptblock invocation semantics are very different, and ideally the rule would fire in the second but not the first case. That requires a fair amount of work. |
Any news on this? |
This report seems to be the same as #1472. |
correct, marking as duplicate of #1472 |
This issue has been marked as duplicate and has not had any activity for 1 day. It will be closed for housekeeping purposes. |
Before submitting a bug report:
Steps to reproduce
Expected behavior
No warnings.
Actual behavior
$param
has an PSReviewUnusedParameter warning.Environment data
The text was updated successfully, but these errors were encountered: