-
Notifications
You must be signed in to change notification settings - Fork 388
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
Fix PSUseConsistentIndentationRule to handle pipes correctly when there is a multi-line statement after a pipe and add PipelineIndentation customisation option for it #1102
Fix PSUseConsistentIndentationRule to handle pipes correctly when there is a multi-line statement after a pipe and add PipelineIndentation customisation option for it #1102
Conversation
…re is a multi-line statement after it: Do not just add temporary indentation for the next line but keep the indentation level
Rules/UseConsistentIndentation.cs
Outdated
{ | ||
AddViolation(token, indentationLevel++, diagnosticRecords, ref onNewLine); | ||
} | ||
else if (pipelineIndentationStyle == PipelineIndentationStyle.IncreaseIndentationForFirstPipeline) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use break
above and eliminate else
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this would probably be more natural as a switch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the proposed break statement in the first if
statement to convert the else if
to an if
statement in this commit. A switch statement for 2 cases (out of 3 enum values) is not worth the horizontal space IMHO and does not feel more readable to me (as a reader, I expect a switch statement to go through all enum values). I had to force-push once because the git pull -r
that I had to do due to the committed suggestions, messed up the branch so I had to revert that and pull again normally with a clean merge commit. Shall I merge now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall I merge now?
LGTM
Co-Authored-By: bergmeister <[email protected]>
cde7090
to
f2a518f
Compare
…nalyzer into FixConsistentIndentationForPipeWithCommandInside
…re is a multi-line statement after a pipe and add PipelineIndentation customisation option for it (PowerShell#1102) * Fix PSUseConsistentIndentationRule to handle pipes correctly when there is a multi-line statement after it: Do not just add temporary indentation for the next line but keep the indentation level * correctly decrement indentation count for multiple pipes * add customisation * take pipeline into account and add docs. TODO: Change shipped setting files * update formatting setting files * add tests and refactor/improve test suite * Apply suggestions from code review Co-Authored-By: bergmeister <[email protected]> * Remove else block by using break
PR Summary
Fixes #1066
Do not just add temporary indentation for the next line but keep the indentation level for the next lines and then decrement it, this allows to handle multiline statements.
This adds the new option
PipelineIndentation
with the 3 options:This PR also fixes a small bug with the auto-correction if a pipe is on the same line where indentation has to be corrected (regression test case added) and improves the test suite
PR Checklist
.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
to the beginning of the title and remove the prefix when the PR is ready.