-
Notifications
You must be signed in to change notification settings - Fork 395
PSUseDeclaredVarsMoreThanAssignments is thrown incorrectly #903
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I believe that this is correctly throwing the PSScriptAnalzyer warning as on each iteration of This is due to the I would recommend using |
In my example, $totalSize is an integer and it provides the correct answer. It is demonstrably NOT being recreated in the execution block. Your analysis isn't accurate. |
Further back and forth led me to discover that the problem with PSSA rules seems to be "+=". If I change "$totalSize += $.Length" to "$totalSize = $totalSize + $.Length" then PSSA quits complaining. That being said, see Jason Shirk's email of 21-Feb to psmvps describing a class of bugs (which includes this one). |
This seems to be a duplicate of #636 to me and that @kilasuit is right about the warning being ok, therefore I would like to close this issue if you are OK with that? There are various known issues with |
I agree that its a duplicate of #636 (once I discovered the workaround). I do not agree with @kilasuit 's analysis (and neither did Jason Shirk). The warning is not ok. Jason's email on the topic:
|
@swngdnz That's fine, it is totally OK to disagree and discuss it. Thanks for providing more details and contributing to the discussion. Personally I am not 100% sure on which side I really am but Jason is usually the expert in this topic. It is good to first lay down examples to know what the expected behaviour is (which is really non-trivial as we see here) but the bottom line to me is also that one needs to think about better design ideas (because this is the underlying issue here) in order to make the rule better. I am wondering if it is better to have e.g. a monthly community call to discuss such issues together or follow an RFC like approach similar to the PowerShell core repo where a technical details are being proposed (so that everyone can read and think about it beforehand) and then discuss it together. |
Hi... I don't know your email address, but perhaps you could consider joining the PSMVP mailing list. We do discuss these things there (and PSSA has been a fairly popular topic). On this specific issue, using $script:variablename is another workaround. Is it NOT a solution to the problem. As a specific comment, I have NO idea where or why @kilasuit introduced an array. That is NOT, and never was, part of my original post. It makes a significant impact on the proper decision and result. Perhaps both a monthly call and an RFC would be good. The challenge is that users of PSSA (and PS in general) are worldwide. The monthly call works primarily for Western Europe and the Americas. The RFC allows for the rest of the world to contribute. |
Oh, and @lzybkr is Jason. I had to look up his GitHub user. This comment is to wrap him in. |
@swngdnz Is the PSMVP mailing list not public? I would rather prefer to discuss issues in public here especially since other folks can learn from the discussions as well. Although I am not a friend of emails (following Scott Hanselman's advice of |
The PSVMP mailing list is not public. The discussion should take place here. |
I have a fix for this now, therefore I will extract the cases from Jason's valuable email into a new issue because the awareness of whether a scriptblock is being executed or dot sourced is a different issue. |
Steps to reproduce
Expected behavior
On line 7, nothing should be reported.
Actual behavior
On line 7, $totalSize is underlined with a green squiggle, "The variable 'totalSize' is assigned but never used. (PSUseDeclaredVarsMoreThanAssignments)"; which is obviously false.
The text was updated successfully, but these errors were encountered: