Skip to content
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

Conversation

bergmeister
Copy link
Collaborator

@bergmeister bergmeister commented Nov 14, 2018

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:

  • IncreaseIndentationForFirstPipeline (default as this was voted to be the most popular option, see here)
  • IncreaseIndentationAfterEveryPipeline
  • NoIndentation

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

bergmeister added 2 commits Nov 14, 2018
…re is a multi-line statement after it: Do not just add temporary indentation for the next line but keep the indentation level
@bergmeister bergmeister added this to the 1.18 milestone Nov 15, 2018
@bergmeister bergmeister changed the title WIP Fix PSUseConsistentIndentationRule to handle pipes correctly when there is a multi-line statement after a pipe Fix PSUseConsistentIndentationRule to handle pipes correctly when there is a multi-line statement after a pipe Nov 15, 2018
@bergmeister bergmeister self-assigned this Nov 15, 2018
@bergmeister bergmeister changed the title Fix PSUseConsistentIndentationRule to handle pipes correctly when there is a multi-line statement after a pipe Fix PSUseConsistentIndentationRule to handle pipes correctly when there is a multi-line statement after a pipe and add PipelineIndentation customisation option for it Nov 26, 2018
@bergmeister bergmeister requested review from kapilmb and JamesWTruher and removed request for kapilmb Nov 26, 2018
bergmeister added 2 commits Jan 8, 2019
…nalyzer into FixConsistentIndentationForPipeWithCommandInside
…nalyzer into FixConsistentIndentationForPipeWithCommandInside
@bergmeister bergmeister added the (Re-)Review Needed label Jan 29, 2019
rjmholt
rjmholt approved these changes Mar 5, 2019
Rules/UseConsistentIndentation.cs Outdated Show resolved Hide resolved
{
AddViolation(token, indentationLevel++, diagnosticRecords, ref onNewLine);
}
else if (pipelineIndentationStyle == PipelineIndentationStyle.IncreaseIndentationForFirstPipeline)
Copy link
Contributor

@rjmholt rjmholt Mar 5, 2019

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

Copy link
Contributor

@rjmholt rjmholt Mar 5, 2019

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

Copy link
Collaborator Author

@bergmeister bergmeister Mar 5, 2019

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?

Copy link
Contributor

@rjmholt rjmholt Mar 5, 2019

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

Rules/UseConsistentIndentation.cs Outdated Show resolved Hide resolved
Co-Authored-By: bergmeister <c.bergmeister@gmail.com>
@bergmeister bergmeister force-pushed the FixConsistentIndentationForPipeWithCommandInside branch from cde7090 to f2a518f Compare Mar 5, 2019
@bergmeister bergmeister merged commit c366328 into PowerShell:development Mar 5, 2019
2 checks passed
bergmeister added a commit to bergmeister/PSScriptAnalyzer that referenced this issue Mar 22, 2019
…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 <c.bergmeister@gmail.com>

* Remove else block by using break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area - Formatter (Re-)Review Needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants