Skip to content

Wrong indent for pipelines #4252

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
6 tasks done
aelij opened this issue Nov 8, 2022 · 10 comments
Closed
6 tasks done

Wrong indent for pipelines #4252

aelij opened this issue Nov 8, 2022 · 10 comments
Labels
Issue-Bug A bug to squash. Resolution-Answered Will close automatically.

Comments

@aelij
Copy link

aelij commented Nov 8, 2022

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

PowerShell allows line breaks in pipelines without a backtick. I would expect the editor to indent it as if the backtick was present.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.2.7
PSEdition                      Core
GitCommitId                    7.2.7
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.73.0
8fa188b2b301d36553cbc9ce1b0a146ccb93351f

Extension Version

Steps to Reproduce

Expected:

Get-ChildItem |
  Select-Object Name

Get-ChildItem | `
  Select-Object Name

Actual:

Get-ChildItem |
Select-Object Name

Get-ChildItem | `
  Select-Object Name

Visuals

No response

Logs

No response

@aelij aelij added the Issue-Bug A bug to squash. label Nov 8, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Nov 8, 2022
@aelij aelij changed the title Wrong ident for pipelines Wrong indent for pipelines Nov 8, 2022
@andyleejordan
Copy link
Member

Formatting is done via PSScriptAnalyzer, can you test if this repros independently via PSSA without the editor? That is, run the repro through Invoke-Formatter and see what happens 😄

@andyleejordan andyleejordan added Needs: Author Feedback Please give us the requested feedback! and removed Needs: Triage Maintainer attention needed! labels Nov 8, 2022
@aelij
Copy link
Author

aelij commented Nov 10, 2022

Invoke-Formatter (version 1.21.0) works as expected

> Invoke-Formatter -ScriptDefinition 'Get-ChildItem |
>> Select-Object Name'
Get-ChildItem |
    Select-Object Name

@ghost ghost added Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Author Feedback Please give us the requested feedback! labels Nov 10, 2022
@RansomVO
Copy link

RansomVO commented Nov 23, 2022

I have a similar issue which started after I did an update last week. In my case formatting is ignoring the Code Formatting settings:

  • New Line After Close Brace
  • New Line After Open Brace
  • Open Brace On Same Line

And it reformats my scripts completely.
formatter

@aelij
Copy link
Author

aelij commented Nov 27, 2022

@RansomVO I suggest you open a separate issue for this

@RansomVO
Copy link

@aelij Opened #4283

@andyleejordan
Copy link
Member

@aelij What do you have your powershell.codeFormatting.preset set to? If it's anything other than Custom (the default) then my understanding is that it will override the other settings.

@andyleejordan
Copy link
Member

@aelij oh, re-reading your issue, I think for your expected scenario you just need to configure powershell.codeFormatting.pipelineIndentationStyle. The default (and I don't know why) is NoIndentation but if you set it to IncreaseIndentationForFirstPipeline it will (mostly) do what you want. In testing, though, I discovered that the second block of code will double-indent, and I'm not sure why, but probably because scripts aren't really expected to use | <backtick> at the end of a line since both | and <backtick> are line-continuations in PowerShell scripts.

@andyleejordan andyleejordan added Resolution-Answered Will close automatically. and removed Needs: Maintainer Attention Maintainer attention needed! labels Dec 1, 2022
@ghost ghost closed this as completed Dec 2, 2022
@ghost
Copy link

ghost commented Dec 2, 2022

This issue has been marked as answered and has not had any activity in a day. It has been automatically closed for housekeeping purposes.

@aelij
Copy link
Author

aelij commented Dec 7, 2022

@andschwa Can we change the default? It doesn't make sense IMO

@andyleejordan
Copy link
Member

@aelij I agree, and so I opened an RFC here, please do share your comment: #4296

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug A bug to squash. Resolution-Answered Will close automatically.
Projects
None yet
Development

No branches or pull requests

3 participants