Skip to content

PSScriptAnalyzer incorrectly scopes variables in begin/process/end scriptblock #804

Open

Description

PSScriptAnalyzer incorrectly adds scope to begin/process/end scriptblocks when it should treat them as one scope:

hashtable

Activity

  1. TimCurwick commented on Aug 1, 2017

    @TimCurwick
    Contributor

    This also happens in the ForEach method:

    $Script = @'
    $A = @()
    (1..2).ForEach{ $A += $_ }
    $A
    '@
    
    Invoke-ScriptAnalyzer -ScriptDefinition $Script | Select -ExpandProperty Message
    

    The variable 'A' is assigned but never used.

  2. desk7 commented on Mar 19, 2023

    @desk7

    Bug still exists today and it is very annoying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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