-
Notifications
You must be signed in to change notification settings - Fork 382
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: Add CommandsToTraverse option #1921
Conversation
Explicitly included Where-Object and ForEach-Object scriptblocks to also be searched for variable use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're definitely going to need new validation for this behavior.
Please create tests for this.
@FriedrichWeinmann We plan to release later this month so if you could add some tests, we could potentially merge and ship this in time? |
Sorry about the delay, added tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FriedrichWeinmann Thanks for adding tests, whilst reviewing I just noticed that we need to document this new option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great - thanks for adding the tests
PR Summary
Proposed resolution of the issue of PSReviewUnusedParameter not traversing into scriptblocks of common commands such as Where-Object or ForEach-Object (#1472).
Implementation:
Where-Object
andForEach-Object
explicitly to the list of commands to traverseNotes & Thoughts
This is currently not too refined, but works for what it does.
Does not address
$using
use in Invoke-Command or other edge cases (e.g.ForEach-Object -Parallel
).But it does solve the problem for the most common everyday usage and allows extensibility for people with custom needs (e.g. I'm going to explicitly include
Invoke-PSFProtectedCommand
).Also does not cover special cases, such as calculated properties of
Select-Object
. Or scriptblocks stored in variables and later used as argument for commands that are whitelisted. Maybe more detailed configuration options needed for cases like that.PR Checklist
.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
to the beginning of the title and remove the prefix when the PR is ready.