-
Notifications
You must be signed in to change notification settings - Fork 391
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
PSUseConsistentIndentation: Indentation wrong if pipeline is wrapped in parentheses #1407
Comments
Thanks for raising it and the level of detail. Very interesting and important. Next week is busy for me, but it's definitely on my tracker to investigate more. In the meantime I verified that the behaviour repros in master as well. |
A more minimalistic repro is: (foo | bar {
baz
}) The parenthesis are 'causing' it to happen. I will investigate now what the root cause is in terms of code |
Update: The indentation being one level too much on line 2 and 3 of the above minimal repro is being 'caused' by the left parenthesis and left brace both causing the indentation to increase by one level, which is one level too much here due to them both applying in this scenario. The code that does this is here: PSScriptAnalyzer/Rules/UseConsistentIndentation.cs Lines 145 to 152 in f389aa4
I didn't write this code but I think the idea is to provide indentation for the following scenarios that both apply in this special case # Indentation after brace
if ($foo) {
bar
}
# Indendation of multi-line condition
if ($foo -and
$bar) { ... } Do you agree with my reasoning of isolating this special case or do you see more cases? This behaviour is actually not new and happens also with older version such as e.g. 1.17.1 and 1.18.1, therefore is not a regression or related to the new @SydneyhSmith Since this is not a regression, I consider it to have lower priority, is it worthwhile having a label of its own? |
@felixfbecker Thinking about this again, it feels like the best fix for this would be to tweak the logic for |
You probably still want to allow something like this though: $result = (
Get-Something | Get-SomethingElse | Get-Another
).Property (it would look bad if line 2 was not indented) |
@felixfbecker Good thinking. Thinking harder about the different use cases, it feels like |
We should identify some cases where we think parens should and shouldn't increase indentation before proceeding I think, so that we don't end up oscillating between solutions that go too far in either direction. I don't often use parens like this myself, so I don't have as good a feel for it as you might. My thinking is:
|
Before submitting a bug report:
Steps to reproduce
Format one of these files:
https://github.com/pcgeek86/PSGitHub/blob/5fa152568f3218843bbec97c5604d6b16b03066f/Functions/Private/ConvertTo-ColoredPatch.ps1
https://github.com/pcgeek86/PSGitHub/blob/5fa152568f3218843bbec97c5604d6b16b03066f/Functions/Public/Merge-GitHubPullRequest.ps1
https://github.com/pcgeek86/PSGitHub/blob/5fa152568f3218843bbec97c5604d6b16b03066f/Functions/Public/New-GitHubReleaseAsset.ps1
https://github.com/pcgeek86/PSGitHub/blob/5fa152568f3218843bbec97c5604d6b16b03066f/Functions/Public/New-GitHubReview.ps1
https://github.com/pcgeek86/PSGitHub/blob/5fa152568f3218843bbec97c5604d6b16b03066f/Functions/Public/Set-GitHubToken.ps1
with
Expected behavior
Should stay the same
Actual behavior
Following indentation is too much, one for every pair of () it seems, e.g.:
Environment data
The text was updated successfully, but these errors were encountered: