◐ Shell
clean mode source ↗

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-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