Skip to content

Formatter fails for multi-line pipelines when the first line has two or more pipes #1459

Closed
@EklipZgit

Description

@EklipZgit

Issue Description

Under extension settings, set Pipeline Indentation Style to IncreaseIndentationForFirstPipeline (which I think is a more sensible default than No Indentation though I don't know what the official community guidelines say on the topic...).

Then format the following:

# arbitrary code flow structure to create nesting for bug demo
if ($true)
{
    foreach ($i in 0..10)
    {
        $works = $something.Value | 
            Group-Object -NoElement | 
            Where-Object { $_.Count -gt 2 } |
            Sort-Object -Property Count -Descending |
            Select-Object -First 1 -ExpandProperty Name

        $andThisWorks = $something.Value | 
            Group-Object -NoElement | Where-Object { $_.Count -gt 1 } |   # doubled pipeline on non-first line
            Sort-Object -Property Count -Descending |
            Select-Object -First 1 -ExpandProperty Name

        $broken = $something.Value | Group-Object -NoElement | # doubled pipeline on first line
            Where-Object { $_.Count -gt 1 } |
            Sort-Object -Property Count -Descending |
            Select-Object -First 1 -ExpandProperty Name

        $norDoesTripleWork = $something.Value | Group-Object -NoElement | Where-Object { $_.Count -gt 1 } |   # tripled pipeline on non-first line
            Sort-Object -Property Count -Descending |
            Select-Object -First 1 -ExpandProperty Name
    }
}

Output is

# arbitrary code flow structure to create nesting for bug demo
if ($true)
{
    foreach ($i in 0..10)
    {
        $works = $something.Value | 
            Group-Object -NoElement | 
            Where-Object { $_.Count -gt 2 } |
            Sort-Object -Property Count -Descending |
            Select-Object -First 1 -ExpandProperty Name

        $andThisWorks = $something.Value | 
            Group-Object -NoElement | Where-Object { $_.Count -gt 1 } | # doubled pipeline on non-first line
            Sort-Object -Property Count -Descending |
            Select-Object -First 1 -ExpandProperty Name

        $broken = $something.Value | Group-Object -NoElement | # doubled pipeline on first line
        Where-Object { $_.Count -gt 1 } |
        Sort-Object -Property Count -Descending |
        Select-Object -First 1 -ExpandProperty Name

    $norDoesTripleWork = $something.Value | Group-Object -NoElement | Where-Object { $_.Count -gt 1 } | # tripled pipeline on non-first line
    Sort-Object -Property Count -Descending |
    Select-Object -First 1 -ExpandProperty Name
}
}

Attached Logs

Follow the instructions in the README about
capturing and sending logs.

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.16299
VSCode 1.44.1
PowerShell Extension Version 2020.4.2

PowerShell Information

Name Value
PSVersion 5.1.16299.1146
PSEdition Desktop
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.16299.1146
BuildVersion 10.0.16299.1146
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
azurerm-vscode-tools msazurermtools 0.9.0
githistory donjayamanne 0.6.3
gitlens eamodio 10.2.1
powershell-preview ms-vscode 2020.4.2
remote-wsl ms-vscode-remote 0.44.2

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