Skip to content

Invoke-Formatter loses one level of identation after chain with more than 2 commands and script blocks #1378

Open

Description

@joaoe

Steps to reproduce

Input script, formatted already as expected.

Function a {
    Function b {
        Get-Content blah | ? {
            $_ -match foo    
        } | Set-Content bleh

        $AnotherStatement = 1
    }

    Write-Host "hi"
    b
    exit 1
}

a

Expected behavior

The example above after formatted looks the same.

Actual behavior

After a chain of more than 2 commands which spans several lines, the formatter loses one level of indentation. Using $(...) triggers the same problem.

Function a {
    Function b {
        Get-Content blah | ? {
            $_ -match foo
        } | Set-Content bleh

    $AnotherStatement = 1
}

Write-Host "hi"
b
exit 1
}

a

Environment data

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

Activity

  1. bergmeister commented on Dec 1, 2019

    @bergmeister
    Collaborator

    Thanks for taking the time to report the issue.
    Have you set the VS-Code setting powershell.codeFormatting.pipelineIndentationStyle to a non-default value (default is NoIndentation)?
    I cannot reproduce with the default setup. For non-default values of this setting, I can reproduce using the currently release version of 1.18.3, but PR #1359 has fixed this case already (i.e. does not reproduce using a build of the master branch any more) therefore the next release should have this also fixed for non-default values.

  2. joaoe commented on Dec 1, 2019

    @joaoe
    Author

    I don't know how or where to change that value.

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