You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unassigned variable rule does not consider += operator to be an assignment #776
changed the title [-]PSES says variable is assigned but never used. It is used just below[/-][+]Unassigned variable rule does not consider += operator to be an assignment[/+]on May 22, 2017
Maybe you are thinking of #772? I closed it since it was by design (how Pester script works). But yesterday I saw the same problem in a normal PowerShell module when the variable was used in a script block, but assigned outside of the script block. Haven't had the time to submit an issue for that yet.
On the surface #772 looks similar to this case but they are different. In #772, there is no way for PSSA to know if $testParmeters is in the same scope as that of the following it statements, as PSSA doesn't know what Pester does with those script blocks. But in this case PSSA clearly has more knowledge about the SIDMappingOutput variable.
Johan Ljunggren (@johlju) Thanks for the example. This is a bug that we want address as soon as possible. But due to the complexity of the right solution we have not been able to devote enough cycles to solving it yet. But we will definitely try to address most if not all issues related to this rule, in the next few releases.
Activity
daviwil commentedon May 22, 2017
Hey Kapil Borle (@kapilmb), is there a bug tracking this already? Seems like I've seen one but I can't find it.
kapilmb commentedon May 22, 2017
This is a known bug with the
PSUseDeclaredVarsMoreThanAssignmentsrule. It is been tracked at PowerShell/PSScriptAnalyzer#636.[-]PSES says variable is assigned but never used. It is used just below[/-][+]Unassigned variable rule does not consider += operator to be an assignment[/+]daviwil commentedon May 22, 2017
Thanks! I'll keep this bug open to track the issue for the next update, but the fix will come as a part of the next PSScriptAnalyzer update.
johlju commentedon May 22, 2017
Maybe you are thinking of #772? I closed it since it was by design (how Pester script works). But yesterday I saw the same problem in a normal PowerShell module when the variable was used in a script block, but assigned outside of the script block. Haven't had the time to submit an issue for that yet.
daviwil commentedon May 22, 2017
Yeah! That's the one :)
kapilmb commentedon May 22, 2017
On the surface #772 looks similar to this case but they are different. In #772, there is no way for PSSA to know if
$testParmetersis in the same scope as that of the followingitstatements, as PSSA doesn't know what Pester does with those script blocks. But in this case PSSA clearly has more knowledge about theSIDMappingOutputvariable.johlju commentedon May 26, 2017
I got another example of the problem triplec110h describing.
Only one of the variable
$resultis saying 'is assigned but never used'.kapilmb commentedon May 26, 2017
Johan Ljunggren (@johlju) Thanks for the example. This is a bug that we want address as soon as possible. But due to the complexity of the right solution we have not been able to devote enough cycles to solving it yet. But we will definitely try to address most if not all issues related to this rule, in the next few releases.
bergmeister commentedon Mar 30, 2018
@tylerl0706 The bug got fixed in the referenced PR above this comment.
TylerLeonhardt commentedon Mar 30, 2018
Thanks Christoph Bergmeister (@bergmeister)! 🎉