Skip to content

Regression in autoformatting of multiline pipes #2213

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
chriskuech opened this issue Sep 27, 2019 · 6 comments
Closed

Regression in autoformatting of multiline pipes #2213

chriskuech opened this issue Sep 27, 2019 · 6 comments

Comments

@chriskuech
Copy link

Issue Description

I am experiencing a problem with... The formatter. I have NoIndentation set up in my "Pipeline Indentation Style" but it seems to have regressed and is no longer properly formatting my code. I have provided an error case below, but I have also observed issues with Pester test formatting with this pipe style.

Ultimately, we developed this pipe style (backticks and pipe on the same line) to circumvent either prior issues or limitations with the formatter. Now we have a large code base that is growing increasing formatting issues. I would like this resolved, but I am also in any mitigation that can automatically be applied (ie only reformatting without modifying content), so preserving backticks.

Expected formatting

class Image {
    [string]$Registry
    [string]$Repository
    [string]$Name
    [string]$VersionTag

    Image([string] $Tag) {
        $pattern = "(?<registry>)(:(?<port>))?/(:(?<versionTag>.+))"
        if (-not ($Tag -match $pattern)) {
            throw ""
        }

        "Registry", "Port", "Name", "VersionTag" `
        | ForEach-Object { $this.$_ = $Matches[$_] }
    }

    [string] ToString() {
        return ""
    }
}

Observed formatting

class Image {
    [string]$Registry
    [string]$Repository
    [string]$Name
    [string]$VersionTag

    Image([string] $Tag) {
        $pattern = "(?<registry>)(:(?<port>))?/(:(?<versionTag>.+))"
        if (-not ($Tag -match $pattern)) {
            throw ""
        }

        "Registry", "Port", "Name", "VersionTag" `
        | ForEach-Object { $this.$_ = $Matches[$_] }
}

[string] ToString() {
    return ""
}
}

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.18362
VSCode 1.38.1
PowerShell Extension Version 2019.9.0

PowerShell Information

Name Value
PSVersion 6.2.3
PSEdition Core
GitCommitId 6.2.3
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.10032.0 6.2.3
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
azure-account ms-vscode 0.8.4
azurecli ms-vscode 0.4.6
azurerm-vscode-tools msazurermtools 0.6.0
beautify HookyQR 1.5.0
csharp ms-vscode 1.21.3
debugger-for-chrome msjsdiag 4.12.0
hyper-term-theme hsnazar 0.3.0
kusto-syntax-highlighting josin 1.0.1
markdown-converter manuth 3.0.2
powershell ms-vscode 2019.9.0
remote-wsl ms-vscode-remote 0.39.5
team ms-vsts 1.149.2
vscode-apache mrmlnc 1.2.0
vscode-docker ms-azuretools 0.8.1
vscode-eslint dbaeumer 1.9.1
vscode-jest Orta 3.0.2
vscode-kubernetes-tools ms-kubernetes-tools 1.0.4
vscode-markdown-to-clipboard mlewand 0.0.2
vscode-pitch-black-theme viktorqvarfordt 1.2.3
vscode-typescript-tslint-plugin ms-vscode 1.2.2
vscode-yaml redhat 0.5.3
vscode-zipexplorer slevesque 0.3.1
xml DotJoshJohnson 2.5.0
@ghost ghost added the Needs: Triage Maintainer attention needed! label Sep 27, 2019
@chriskuech
Copy link
Author

Possibly related, all three powershell.codeFormatting.pipelineIndentationStyle values result in the same indentation for me. I have confirmed this is not an issue with workspace vs user settings.

This is the only indentation style that is produced by |-suffixed lines:

FirstCommand |
  SecondCommand |
  ThirdCommand

@chriskuech
Copy link
Author

I also just figured out how to revert extension version and can now definitively say that it's a problem with the latest version of the extension.

@TylerLeonhardt
Copy link
Member

Formatting issues are typically caused by PSScriptAnalyzer since we depend on that.

@bergmeister is a maintainer of that project and has been working on this particular formatting rule I believe. What do you think?

@TylerLeonhardt TylerLeonhardt added Needs-Repro-Info and removed Needs: Triage Maintainer attention needed! labels Sep 28, 2019
@bergmeister
Copy link
Contributor

When setting the powershell.codeFormatting.pipelineIndentationStyle setting to NoIndenation I cannot reproduce this (but otherwise I can). Generally speaking I suggest to replace the backtick with the pipeline itself:

foo |
bar

This makes code not only more readable but also does not suffer from this problem for any setting choice and is therefore the suggested solution.
When I implemented the pipelineIndentationStyle feature, I deliberately disregarded your case simply because the backticks are not needed for multi line pipelines and should rather be replaced by the pipeline itself (there is also a PSSA rule of its own to generally avoid backticks due to other problems in PSSA).
Retrospectively looking at it, I should've maybe also offered a 4th setting, which does not touch indentation at all if people do not like any of the 3 settings or scenarios like this. Therefore I might consider this but I am hesitant to make the rule work in this scenario as well, although I will try to give it a best effort.

@ghost ghost added the Needs: Maintainer Attention Maintainer attention needed! label Sep 30, 2019
@SydneyhSmith SydneyhSmith removed the Needs: Maintainer Attention Maintainer attention needed! label Sep 30, 2019
@rjmholt
Copy link
Contributor

rjmholt commented Oct 1, 2019

We investigated this a bit and it seems to be a bug in the non-preview extension only, but we're not sure why yet. For now, the suggestion is to try out the preview extension.

@TylerLeonhardt
Copy link
Member

This is a duplicate of #2214 and will be fixed in the next release.

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

5 participants