Skip to content

PSUseDeclaredVarsMoreThanAssignment not correctly handling array adds #699

Description

Given the following code

$msg = @()
@("a", "b") | ForEach-Object { $msg += $_ }
Write-Information $msg -InformationAction Continue

I get the following warning:

  • The variable 'msg' is assigned but never used. (line 2)

I realize that this generates a new array each time, but it is both being assigned to and read, so this appears to be a false positive.

Another similar scenario:

$params = (@{"a" = 1; "b" = 2}).GetEnumerator() |
    ForEach-Object { $m = @{} } { $m[$_.Name] = $_.Value } { $m } # foreach begin{} process{} end{}
$params
  • The variable 'm' is assigned but never used. (line 2)

Activity

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions