Skip to content

PSUseDeclaredVarsMoreThanAssignment not correctly handling array adds and final assignment #1103

Closed
@HowardWolosky

Description

@HowardWolosky

This is a continuation of Issue #699 which I previously opened. It was closed as being resolved, but this issue remains.

Steps to reproduce

$resourceParams = @('a1', 'b1', c1')
$params = Get-Variable -Name $resourceParams -ErrorAction SilentlyContinue |
                  ForEach-Object { $m = @{} } { $m[$_.Name] = $_.Value } { $m } # foreach begin{} process{} end{}

Expected behavior

No reported issue

Actual behavior

PSUseDeclaredVarsMoreThanAssignments    Warning    The variable 'm' is assigned but never used.

Environment data

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

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.17.1
1.10.0
1.4.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions