Skip to content

Rule Request: UnknownLabel #2145

@iRon7

Description

@iRon7

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions