X Tutup
The Wayback Machine - https://web.archive.org/web/20200918095213/https://github.com/PowerShell/PSScriptAnalyzer/pull/1310
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
merged 4 commits into from Aug 19, 2019

Conversation

@bergmeister
Copy link
Collaborator

bergmeister commented Aug 16, 2019

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

Copy link
Member

rjmholt left a comment

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

Rules/UseDeclaredVarsMoreThanAssignments.cs Outdated Show resolved Hide resolved
Rules/UseDeclaredVarsMoreThanAssignments.cs Outdated Show resolved Hide resolved
…simplify local method
@bergmeister
Copy link
Collaborator Author

bergmeister commented Aug 19, 2019

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?

@bergmeister bergmeister merged commit bba8fed into PowerShell:master Aug 19, 2019
1 of 2 checks passed
1 of 2 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
license/cla All CLA requirements met.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.
X Tutup