Skip to content

PSUseDeclaredVarsMoreThanAssignment not correctly handling array adds #699

Closed
@HowardWolosky

Description

@HowardWolosky

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)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions