Skip to content

Wrong indentation for passed scriptblocks in pipe sequence (PSUseConsistentIndentation) #1066

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

Closed
felixfbecker opened this issue Sep 4, 2018 · 2 comments · Fixed by #1102
Closed

Comments

@felixfbecker
Copy link

felixfbecker commented Sep 4, 2018

Steps to reproduce

Get-ChildItem *.yml |
    Get-Content -Raw |
    ConvertFrom-KubeYaml |
    ForEach-Object {
        switch ($_.Metadata.Name) {
            # ...
        }
    } |
	Update-KubeResource

Expected behavior

Should not cause a rule violation, this is the expected formatting

Actual behavior

Formats to:

Get-ChildItem *.yml |
    Get-Content -Raw |
    ConvertFrom-KubeYaml |
    ForEach-Object {
    switch ($_.Metadata.Name) {
        # ...
    }
} |
    Update-KubeResource

Note how the switch is not indented and the closing brace of the scriptblock is on the wrong level, while the next pipeline element is correct.

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-rc.1
PSEdition                      Core
GitCommitId                    6.1.0-rc.1
OS                             Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64
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.17.1
@bergmeister
Copy link
Collaborator

bergmeister commented Nov 5, 2018

Thanks for raising it and sorry for coming back quite late to this. This has annoyed me sometimes as well. I will start to look into this so that we hopefully have a fix in the next version of PSSA

@bergmeister
Copy link
Collaborator

bergmeister commented Nov 14, 2018

I had a look at this, a slightly more simplified example for this issue is (the problem is that there is more than 1 line after 1 pipeline)

Get-ChildItem |
    ForEach-Object {
        $_.ToString()
}

I will try to see if I can come up with a fix for this, as far as I can see, pipes are being catered for but the author decided to give them only 'temporary' indentation for the next line after the ppipe because the rule only looks at tokens and therefore does not know when the pipe ends. I will try to see if I can fix this.
@felixfbecker Why do you not expect the correct formatting to be this?

Get-ChildItem *.yml |
    Get-Content -Raw |
        ConvertFrom-KubeYaml |
            ForEach-Object {
                switch ($_.Metadata.Name) {
                    # ...
            }
        } |
	       Update-KubeResource

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