Fix indentCase handling (fixes #2442)#2443
Draft
stackotter wants to merge 3 commits intonicklockwood:developfrom
Draft
Fix indentCase handling (fixes #2442)#2443stackotter wants to merge 3 commits intonicklockwood:developfrom
stackotter wants to merge 3 commits intonicklockwood:developfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2443 +/- ##
===========================================
- Coverage 95.28% 95.24% -0.04%
===========================================
Files 165 165
Lines 25147 25167 +20
===========================================
+ Hits 23962 23971 +9
- Misses 1185 1196 +11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Author
|
@bbrk24 pointed out that this wouldn't handle nested switch statements so I've converted this to a draft for now. Will come back and fix that another day (by updating my implementation to use stacks). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As described in #2442, the
indentCaseformatting option has some unexpected behaviour. I've updated handling ofindentCaseinResult/Indent.swiftto match my mental model of whatindentCasedoes.My mental model for
indentCaseis that it should lead to identical behaviour to the default switch statement formatting behaviour except with the entire body of the switch statement indented an additional level.This mental model lines up with SwiftFormat's behaviour in most cases. The only exceptions that I know of are #2442, and the
testIndentSwitchCaseWheretest case which I had to update after my changes. My justification for updating thetestIndentSwitchCaseWheretest case rather than changing my implementation to preserve the behaviour that it originally tested for is that if you run that same test case withoutindentCaseyou get the samewhereclause wrapping behaviour as my implementation; and it doesn't make sense to me thatwhereclause wrapping should be affected by theindentCaseoption.Implementation
In order to implement this new behaviour, I ripped out all existing
indentCasehandling (which was originally spread all through theapplyIndentimplementation), and replaced it with a more direct approach. Most of the new code is used to detect whether a given{token is the start of aswitchstatement body, and similarly whether a given}token is the end of aswitchstatement body. IfindentCaseis enabled, then I add one more level of indentation (and push it onto the indentation scope so thatcase's scope-ending behaviour doesn't mess things up) when aswitchbody begins, and remove it when aswitchbody ends.