Skip to content

PSUseDeclaredVarsMoreThanAssignment in read(only) scope #1109

@iRon7

Description

@iRon7

Steps to reproduce

I am not sure whether this is a duplicate of #636 and/or the implication is completely understood:

Function Get-A {$a}
Function Get-B {
	$a = 1
	Get-A
}
Get-B

Expected behavior

No reported issue

Actual behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSUseDeclaredVarsMoreThanAssignment Warning      Analyzer.p 3     The variable 'a' is assigned but never used.
s                                                s1

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Used case:
https://github.com/iRon7/ConvertTo-Expression/blob/master/ConvertTo-Expression.ps1

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSUseDeclaredVarsMoreThanAssignment Warning      ConvertTo- 208   The variable 'Space' is assigned but never used.
s                                                Expression
                                                 .ps1
PSUseDeclaredVarsMoreThanAssignment Warning      ConvertTo- 208   The variable 'LineUp' is assigned but never used.
s                                                Expression
                                                 .ps1

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.17134.407
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.407
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

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