Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-Formatter: indent a block even though it should not #1933

Open
Jiehong opened this issue Aug 18, 2023 · 1 comment
Open

Invoke-Formatter: indent a block even though it should not #1933

Jiehong opened this issue Aug 18, 2023 · 1 comment

Comments

@Jiehong
Copy link

Jiehong commented Aug 18, 2023

Before submitting a bug report:

Note: this has nothing to do with VSCode, only the Invoke-Formatter cmdlet.

Steps to reproduce

Save the following file as test.ps1:

$PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainText;

$knownProperties = @()
Get-ChildItem -Path . -Recurse -Filter pom.xml | ForEach-Object {
    [xml]$pom = Get-Content $_
    $knownProperties += $pom.project.properties.getEnumerator() |
        Where-Object name -NE '#comment' |
        ForEach-Object name
    }

Get-ChildItem -Path . -Recurse -Filter property-*-report.xml | ForEach-Object {
    [xml]$report = Get-Content $_
    $report.PropertyUpdatesReport.properties.property |
        Where-Object { $_.lastVersion -NE $null -and $_.propertyName -in $knownProperties }

    } | Select-Object propertyName, lastVersion | Sort-Object propertyName -Unique

Then, run the formatter:

Invoke-Formatter -ScriptDefinition (Get-Content -Raw -Path ./test.ps1)

Expected behavior

$PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainText;

$knownProperties = @()
Get-ChildItem -Path . -Recurse -Filter pom.xml | ForEach-Object {
    [xml]$pom = Get-Content $_
    $knownProperties += $pom.project.properties.getEnumerator() |
        Where-Object name -NE '#comment' |
        ForEach-Object name
    }

Get-ChildItem -Path . -Recurse -Filter property-*-report.xml | ForEach-Object {
    [xml]$report = Get-Content $_
    $report.PropertyUpdatesReport.properties.property |
        Where-Object { $_.lastVersion -NE $null -and $_.propertyName -in $knownProperties }

    } | Select-Object propertyName, lastVersion | Sort-Object propertyName -Unique

Actual behavior

The second line starting with Get-ChildItem gets indented and all its pipeline, for no apparent reason:

$PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainText;

$knownProperties = @()
Get-ChildItem -Path . -Recurse -Filter pom.xml | ForEach-Object {
    [xml]$pom = Get-Content $_
    $knownProperties += $pom.project.properties.getEnumerator() |
        Where-Object name -NE '#comment' |
        ForEach-Object name
    }

    Get-ChildItem -Path . -Recurse -Filter property-*-report.xml | ForEach-Object {
        [xml]$report = Get-Content $_
        $report.PropertyUpdatesReport.properties.property |
            Where-Object { $_.lastVersion -NE $null -and $_.propertyName -in $knownProperties }

        } | Select-Object propertyName, lastVersion | Sort-Object propertyName -Unique

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.3.6
PSEdition                      Core
GitCommitId                    7.3.6
OS                             Darwin 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:21:53 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6020
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.21.0
@JamesWTruher
Copy link
Member

@bergmeister - didn't you fix some of these indentation issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants