Formatting indentation issues around the closing brace of pipeline script block
See original GitHub issueThere 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:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
@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: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:
Does that help? Do you still think this is an issue?