FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Enhance UseDeclaredVarsMoreThanAssignments to detect also take into account the usage of Get-Variable with an array of variables and usage of named parameter -Name by bergmeister · Pull Request #1310 · PowerShell/PSScriptAnalyzer · GitHub

Enhance UseDeclaredVarsMoreThanAssignments to detect also take into account the usage of Get-Variable with an array of variables and usage of named parameter -Name - #1310

Merged
Christoph Bergmeister (bergmeister) merged 4 commits into
PowerShell:masterfrom
bergmeister:get-variable_ParseArray
Aug 19, 2019

Conversation

Copy link
Copy Markdown
Collaborator

PR Summary

Fixes #1301 by enhancing the parsing of the Get-Variable AST to also check if an array is passed or if the -Name parameter is used as a named parameter (including cases where it is shortened to -n).
Also refactored logic into it's own static method for better readability and performance.
Since reverse engineering a CommandAst into the used parameters is quite complex, I am not going to further enhance it.

PR Checklist

Rob Holt (rjmholt) left a comment
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This makes me think we should really invest in some general purpose AST functionality (like parameter parsing/binding tools) (but probably don't have the time currently).

Otherwise, LGTM

Copy link
Copy Markdown
Collaborator Author

Yes, I agree something like a parameter binder helper would be nice but I think it would require the runtime and be no purely static just based on the AST. Maybe some of the parameter binder functionality in PowerShell could be exposed?

Christoph Bergmeister (bergmeister) merged commit bba8fed into PowerShell:master Aug 19, 2019
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PSUseDeclaredVarsMoreThanAssignments reported on "get-variable -include var1,var2"

3 participants


Back | FazBrowse Home | New Git URL