GeezerVison is showing github.com — PSReviewUnusedParameter: Add CommandsToTraverse option by FriedrichWeinmann · Pull Request #1921 · PowerShell/PSScriptAnalyzer
Conversation
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:
- Added a new rule setting: traverseList (string[]). Scriptblocks provided as parameter to one of the listed commands will also be checked for variables.
- Added
Where-Object and ForEach-Object explicitly to the list of commands to traverse
Notes & 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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Daleyon reacted with thumbs up emoji
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
FriedrichWeinmann and bergmeister reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Sorry about the delay, added tests
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Mar 16, 2024
Reviewers
+1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|