Skip to content

PSScriptAnalyzer incorrectly flags a variable as assigned but never used #989

Closed

Description

System Details

  • Windows 10 1511
  • VS Code Version: 1.14.2
  • PowerShell extension version: 1.4.1
  • $PSVersionTable

PSVersion 5.0.10586.962
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.962
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1


Issue Description

When a variable is declared either in the begin block or statement block of a ForEach-Object pipeline, the PSScriptAnalyzer incorrectly flags it as assigned but never used.

Examples:
$Count is incorreclty flagged as assigned but never used
$myArray = @()
$myArray += "Item1"
$myArray += "Item2"
$myArray += "Item3"
$myArray += "Item4"
$myArray | ForEach-Object {$Count = 0} {$Count++; $Count}

Activity

  1. daviwil commented on Aug 14, 2017

    @daviwil
    Contributor

    This is covered by PowerShell/PSScriptAnalyzer#711, will close this issue in favor of that one.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions