Skip to content
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

Unassigned variable rule does not consider += operator to be an assignment #776

Closed
triplec110h opened this issue May 22, 2017 · 10 comments · Fixed by PowerShell/PSScriptAnalyzer#935
Labels
Issue-Bug A bug to squash.

Comments

@triplec110h
Copy link

System Details

  • Operating system name and version:
  • VS Code version: 1.12.2
  • PowerShell extension version: 1.1.0
  • Output from $PSVersionTable:
Copy / paste the below commands into the PowerShell Integrated Terminal, and paste the output here

code -v
1.12.2
19222cdc84ce72202478ba1cec5cb557b71163de

$pseditor.EditorServicesVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
1      1      0      0

code --list-extensions --show-versions
[email protected]
[email protected]

$PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.14393.1066
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.1066
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

I am experiencing a problem with...
PSES says variable is assigned but never used. It is used just below - see screenshot
2017-05-22_11-36-46

Attached Logs

Follow the instructions in the README
about capturing and sending logs.

@daviwil
Copy link
Contributor

daviwil commented May 22, 2017

Hey @kapilmb, is there a bug tracking this already? Seems like I've seen one but I can't find it.

@kapilmb
Copy link

kapilmb commented May 22, 2017

This is a known bug with the PSUseDeclaredVarsMoreThanAssignments rule. It is been tracked at PowerShell/PSScriptAnalyzer#636.

@daviwil daviwil 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 May 22, 2017
@daviwil daviwil added this to the 1.2.0 milestone May 22, 2017
@daviwil
Copy link
Contributor

daviwil commented 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
Copy link

johlju commented 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
Copy link
Contributor

daviwil commented May 22, 2017

Yeah! That's the one :)

@kapilmb
Copy link

kapilmb commented 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 $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.

@daviwil daviwil modified the milestones: 1.2.0, June 2017 May 24, 2017
@johlju
Copy link

johlju commented May 26, 2017

I got another example of the problem @triplec110h describing.

Only one of the variable $result is saying 'is assigned but never used'.

image

image

@kapilmb
Copy link

kapilmb commented May 26, 2017

@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
Copy link
Contributor

@tylerl0706 The bug got fixed in the referenced PR above this comment.

@TylerLeonhardt
Copy link
Member

Thanks @bergmeister! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug A bug to squash.
Projects
None yet
6 participants