Skip to content

Module exported variables should not be flagged with PSUseDeclaredVarsMoreThanAssignment #819

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

Open
dantraMSFT opened this issue Sep 19, 2017 · 2 comments

Comments

@dantraMSFT
Copy link

Repro: In a module, define and assign a variable then export it using Export-ModuleMember -Variable


$MyVariable = 'some value'
Export-ModuleMember -Variable MyVariable

Expected: Invoke-ScriptAnalyzer does not flag the variable as unused.
Actual:
file: 'file:MyModule.psm1'
severity: 'Warning'
message: 'The variable 'MyVariable' is assigned but never used. (PSUseDeclaredVarsMoreThanAssignments)'

@JamesWTruher
Copy link
Contributor

@dantraMSFT
Some things will be rather difficult to do, providing a partial solution should be doable, but something like the following might not be possible via inspection (given the following m.psm1 file)

$var1 = 1
$var2 = "a"
$vars = "var1","var2"
Export-ModuleMember -Variable $vars

It would be quite difficult to catch that via the ast since it means getting a runtime value, would a partial solution be better than no solution?

@ghost
Copy link

ghost commented Aug 11, 2018

+1 on the request. A partial solution -- by which I assume you mean a simple parse to locate an export that matches an assigned but otherwise unused variable -- would work for me.

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

3 participants