PSReviewUnusedParameter: Add CommandsToTraverse option#1921
Merged
bergmeister merged 5 commits intoPowerShell:masterfrom Feb 13, 2024
FriedrichWeinmann:master
Merged
PSReviewUnusedParameter: Add CommandsToTraverse option#1921bergmeister merged 5 commits intoPowerShell:masterfrom FriedrichWeinmann:master
bergmeister merged 5 commits intoPowerShell:masterfrom
FriedrichWeinmann:master
Conversation
Explicitly included Where-Object and ForEach-Object scriptblocks to also be searched for variable use
JamesWTruher
suggested changes
Sep 11, 2023
Contributor
JamesWTruher
left a comment
There was a problem hiding this comment.
we're definitely going to need new validation for this behavior.
Please create tests for this.
Collaborator
|
@FriedrichWeinmann We plan to release later this month so if you could add some tests, we could potentially merge and ship this in time? |
Contributor
Author
|
Sorry about the delay, added tests |
bergmeister
requested changes
Feb 1, 2024
Collaborator
bergmeister
left a comment
There was a problem hiding this comment.
@FriedrichWeinmann Thanks for adding tests, whilst reviewing I just noticed that we need to document this new option.
JamesWTruher
approved these changes
Feb 13, 2024
Contributor
JamesWTruher
left a comment
There was a problem hiding this comment.
looks great - thanks for adding the tests
BenedekFarkas
added a commit
to Lombiq/PowerShell-Analyzers
that referenced
this pull request
May 15, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-ObjectandForEach-Objectexplicitly to the list of commands to traverseNotes & Thoughts
This is currently not too refined, but works for what it does.
Does not address
$usinguse 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,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.