Skip to content

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

Closed
PowerShell/PSScriptAnalyzer
#935

Description

@triplec110h

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
emmanuelbeziat.vscode-great-icons@2.1.4
ms-vscode.PowerShell@1.1.0

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

Activity

  1. daviwil commented on May 22, 2017

    @daviwil
    Contributor

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

  2. kapilmb commented on May 22, 2017

    @kapilmb

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

  3. 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
  4. added this to the 1.2.0 milestone on May 22, 2017
  5. daviwil commented on May 22, 2017

    @daviwil
    Contributor

    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.

  6. johlju commented on May 22, 2017

    @johlju

    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.

  7. daviwil commented on May 22, 2017

    @daviwil
    Contributor

    Yeah! That's the one :)

  8. kapilmb commented on May 22, 2017

    @kapilmb

    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.

  9. johlju commented on May 26, 2017

    @johlju

    I got another example of the problem triplec110h describing.

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

    image

    image

  10. kapilmb commented on May 26, 2017

    @kapilmb

    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.

  11. modified the milestones: July 2017, on Oct 26, 2017
  12. bergmeister commented on Mar 30, 2018

    @bergmeister
    Contributor

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

  13. TylerLeonhardt commented on Mar 30, 2018

    @TylerLeonhardt
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions