Incorrect warning generated by PSScriptAnalyzer #190

Closed
KirkMunro opened this Issue May 21, 2015 · 3 comments

Projects

None yet

3 participants

@KirkMunro

I have a module called HistoryPx. In the manifest, I have the following:

$PSModule.OnRemove = {
# ...
}

$PSModule is initialized outside of this file in a snippet. That causes PSAvoidUnitializedVariable to be raise a warning. However, it seems the assignment that I am performing here is also generating a warning, but the warning is completely undecipherable. Here is the warning type/text:

RuleName: PSUseDeclaredVarsMoreThanAssignments
Message: The variable 'PSModule' is assigned but never used

First, what does PSUseDeclaredVarsMoreThanAssignments even mean? That name doesn't make any sense to me whatsoever.

Second, PSModule is not assigned but never used. In this scenario, I am assigning a value to a property on PSModule.

Third, I was already warned that PSModule is not initialized (even though it is), so why am I receiving another warning at all?

This warning simply doesn't make any sense whatsoever. The name should change to something that clearly indicates what rule is being checked, and the message should change to properly identify what is the issue that is being raised.

You may want to consider leaving the warning out in this case though because you already told me that PSModule is not initialized (which would be the one and only warning I would expect to see if I was assigning a value to a property of an uninitialized variable).

@raghushantha
Member

I believe Quoc fixed this. Quoc?

@raghushantha raghushantha added the bug label Jun 4, 2015
@quoctruong

Yes I fixed the PSUseDeclaredVarsMorehanAssignments bug but not the UninitializedVariable across module.

@quoctruong

Close this as the remaining problem is similar to #189

@quoctruong quoctruong closed this Jun 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment