| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Really clear explanation, thanks for getting to the root of the issue! 🙂 LGTM! |
Sorry, something went wrong.
There was a problem hiding this comment.
Looks good. Sorry for late review. Updated branch from main since CI is now on GitHub Actions. If it passed, happy to merge if Andy Jordan (@andyleejordan) is ok as well?
Sorry, something went wrong.
|
Nice fix! |
Sorry, something went wrong.
UseDeclaredVarsMoreThanAssignments (PowerShell#2013): skip scope-qualified variable references ($global:, $script:, drive-qualified) when checking for uses of local variables, preventing false negatives. AvoidPositionalParameters (PowerShell#1850): skip commands that have no parameters in the database (e.g. native CLI tools like az). Co-authored-by: Cursor <cursoragent@cursor.com>
| Back | FazBrowse Home | New Git URL |
PR Summary
This PR fixes the following longstanding issue: #1300 (Global variables are erroneously reported as "never used")
The issue exists because Helper.IsVariableGlobalOrEnvironment uses an Ast to key into VariableAnalysisDictionary, calling VariableAnalysis.IsGlobalOrEnvironment on the value returned to determine whether or not the variable is a global. However, in some cases, the key does not exist in the dictionary, resulting in the method returning false. Fortunately, VariableAnalysis.IsGlobalOrEnvironment depends on no instance members, instead relying solely on the properties of VariableExpressionAst, which is passed in. As such, VariableAnalysis.IsGlobalOrEnvironment can be made static with no consequence, allowing Helper.IsVariableGlobalOrEnvironment to call the method without the dictionary operations.
Also of note, the current implementation is somewhat redundant, with UseDeclaredVarsMoreThanAssignments.AnalyzeScriptBlockAst checking VariablePath.DriveName separately, which is why the issue does not affect environment variables despite VariableAnalysis.IsGlobalOrEnvironment erroneously returning false in some cases.
PR Checklist