PSReviewUnusedParameter: Add CommandsToTraverse option by FriedrichWeinmann · Pull Request #1921 · PowerShell/PSScriptAnalyzer
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-ObjectandForEach-Objectexplicitly 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
- PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- Summarized changes
- Change is not breaking
- Make sure all
.cs,.ps1and.psm1files have the correct copyright header - Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
- This PR is ready to merge and is not Work in Progress.
- If the PR is work in progress, please add the prefix
WIP:to the beginning of the title and remove the prefix when the PR is ready.
- If the PR is work in progress, please add the prefix