question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formatting indentation issues around the closing brace of pipeline script block

See original GitHub issue

There appears to be an issue with the closing brace of the first pipeline script block. The brace (and subsequent tokens) are no longer indented with both IncreaseIndentationForFirstPipeline and IncreaseIndentationAfterEveryPipeline.

Expected behavior

$List | Where-Object {
    } |
    ForEach-Object {
    }

Actual behavior

$List | Where-Object {
} |
    ForEach-Object {
    }

Environment data

> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.1237
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1237
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.1
1.20.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
iadcodecommented, Dec 16, 2021

@bergmeister That does help, and the issue as it stands is not an issue. Thank you for responding. A new issue (feature request), https://github.com/PowerShell/PSScriptAnalyzer/issues/1755, has been raised which pertains to the behaviour that is observed, and a possible solution.

0reactions
bergmeistercommented, Dec 15, 2021

@iadcode The other issues is different in the sense that indentation does not get ‘reset’ to the correct level AFTER the pipeline has finished. In your example, it is about indentation in a statement of pipelines. I added this PipelineIndentation configuration and the way it works by design is that it increases indentation on a newline if a line ends with a pipe, see example in docs: https://docs.microsoft.com/powershell/utility-modules/psscriptanalyzer/rules/useconsistentindentation?view=ps-modules#pipelineindentation-string-default-value-is-increaseindentationforfirstpipeline Looking at your example, I struggle to see why the closing brace should be indented, especially consider if there is something in the scriptblock, this is how ‘correct’ (in the eye of the beholder) indentation looks like to me and I think it would look odd if the closing braces where indented by one more layer:

$List | Where-Object {
  $_ -eq 'foo'
} |  ForEach-Object {
  Invoke-Something $_
}

If you structure it to have the newline after the pipe, you get a nice, logical increase in indentation, which is I think the end goal that you are looking for:

$List |
  Where-Object {
    $_ -eq 'foo'
  } |
    ForEach-Object {
      Invoke-Something $_
    }

Does that help? Do you still think this is an issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incorrect Multi-line Pipeline Indentation when inside a ...
In this case, I have the Pipeline Indentation Style set to IncreaseIndentationAfterEveryPipeline but the behavior is similar when using ...
Read more >
Wrong indentation for passed scriptblocks in pipe sequence ...
Note how the switch is not indented and the closing brace of the scriptblock is on the wrong level, while the next pipeline...
Read more >
Suppression of formatting when typing a closing brace ...
Under Tools>Options>Text Editor>C/C++>Formatting>General is an option called “Automatically format block when I type a }”.
Read more >
Eslint expected indentation of 1 tab but found 4 spaces error
Try to disable indent inside .eslintrc.js file rules: { 'indent': 'off' }. this works fine for me.
Read more >
Code Layout and Formatting - PowerShell Practice and Style
Indenting more than 4-spaces is acceptable for continuation lines (when you're wrapping a line which was too long). In such cases you might...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found