PSScriptAnalyzer icon indicating copy to clipboard operation
PSScriptAnalyzer copied to clipboard

Rule Request: UnknownLabel

Open iRon7 opened this issue 2 months ago • 0 comments

Not sure whether this is a PowerShell a bug or feature but fixing it in PowerShell would probably be a break change.

In any case, I think unknown labels should be notified and even deserve an error severity if the label doesn't exist or is outside the concerned loop.

Invoke-ScriptAnalyzer -ScriptDefinition {
    :foo foreach ($a in 1,2,3) {
        $a
        if ($a -ge $b) { break bar }
    }
}.ToString()

Expected Something like:

RuleName           Severity     ScriptName Line  Message
--------           --------     ---------- ----  -------
PSUnknownLabel     Error                   4     The label 'bar' is not known in this context

See also: Pester breaks on functions with unknown label

iRon7 avatar Dec 04 '25 11:12 iRon7