Skip to content

'PSUseDeclaredVarsMoreThanAssignments' in case of env variable #829

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

Closed
ghost opened this issue Nov 11, 2017 · 2 comments
Closed

'PSUseDeclaredVarsMoreThanAssignments' in case of env variable #829

ghost opened this issue Nov 11, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Nov 11, 2017

When you declare an env variable and not use in current script, PSScriptAnalyzer show the PSUseDeclaredVarsMoreThanAssignments warning.

Specific use case: I set the $Env:GIT_WORK_TREE for git configuration; PSScriptAnalyzer show: The variable 'GIT_WORK_TREE' is assigned but never used. (PSUseDeclaredVarsMoreThanAssignments)

@bergmeister
Copy link
Collaborator

bergmeister commented Dec 2, 2017

@robdesideri Thanks for reporting the case, it is a known issue that PSUseDeclaredVarsMoreThanAssignments can produce false positives in certain cases. However I canot repro your problem using PSScriptanalyzer 1.16.1 and PowerShell 5.1:
Invoke-ScriptAnalyzer -ScriptDefinition "$Env:GIT_WORK_TREE=$gitWorkTree" does not return a warning. Please provide more details. Also note that another way of setting environment variables is
[System.Environment]::SetEnvironmentVariable($string)

@bergmeister
Copy link
Collaborator

Closing because it is a duplicate of #631

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant