Repository navigation
Multiline formatting does not indent correctly #1290
Description
Activity
- pinned this issue
on Jul 12, 2019 - unpinned this issue
on Jul 12, 2019 (This might be fixed in PSSA 1.18.1, which you can test with
Install-Module -Scope CurrentUser PSScriptAnalyzer-- PSES should pick that up)Reacted by Christoph Bergmeister and Sydney Smithandrewducker commented
on Jul 13, 2019 AuthorMore actionsI ran that in PowerShell and then restarted VSCode. Same issue.
I've attached a file with the code as formatted. (Renamed to .txt extension so that GitHub will allow upload)
FormattingTest.txtbergmeister commented
on Aug 18, 2019 CollaboratorMore actionsWhilst I can confirm this still happens on the latest version, I'd argue it is not a valid use case because the backtick is not needed when using pipelines.
Your example can be minimized to this simple example that would cause incorrect formatting:foo | ` # hello world baz
However, not using backticks does not cause this malformatting:
foo | # hello world baz
What you observed is because ScriptAnalyzer increases the indentation per backtick and optionally for pipelines as well depending on the
PipelineIndentationsetting (which default toNoIndentationin VS-Code). Whilst backticks are controversial and usually recommended against, I would've closed this issue normally because backticks are not needed but whilst playing with it, I found one edge case where pipelines are not used (i.e. backticks are needed), where it only indents the comment but not the line below, which should be fixed.foo ` #comment -bar
andrewducker commented
on Aug 19, 2019 AuthorMore actionsAh! The problem was that I wasn't aware of the PipelineIndentation setting! Now that I am, it does what I expect, other than your final case. (Which is the same issue as my final case, I think)
Thank you!
andrewducker commented
on Aug 19, 2019 AuthorMore actionsAny idea why pipelines don't default to "IncreaseIndentationForFirstPipeline", which is what I'd expect?
(i.e. a visual indication that the later lines are a continuation of the first one)
That's what the info at https://devblogs.microsoft.com/powershell/powershell-scriptanalyzer-version-1-18-0-released/ indicates it was going to do.
Edit: Never mind, found https://devblogs.microsoft.com/powershell/release-of-powershell-script-analyzer-1-18-1/
bergmeister commented
on Aug 19, 2019 CollaboratorMore actionsThe new
PipelineIndentationfeature was released in 1.18.0 and the default setting of PSScriptAnalyzer itself isIncreaseIndentationForFirstPipeline. However, after the release, a few edge cases were reported where the behaviour is not correct yet. Therefore we changed the VS-Code PowerShell extension to default toNoIndentationto make the bugs in those edge cases not surface in the meantime. The majority of edge cases were fixed in 1.18.1 but we found another edge case after 1.18.1 (and this one), therefore we expect that only starting with 1.18.2 the feature will be mature enough to start making it a default for VS-Code users.
Issue Description
I am experiencing a problem with formatting of multiline commands. Particularly with comments in them. Given the following command, this is how Powershell formats it:
If I put in backticks then the formatter notices:
which is what I would expect.
However, if I then put in comments I get:
Which doesn't look right to me.
Environment Information
Visual Studio Code
PowerShell Information
Visual Studio Code Extensions
Visual Studio Code Extensions(Click to Expand)