I understand that there are many different preferences, but I believe that this particular behaviour is likely not desirable to anyone so it should be changed to something nicer.
I've included an example of the formatting behaviour without indent-case, and I would've expected that the indent-case option would simply indent the entire case block (which would achieve my preferred style), but instead it seems to only indent the opening case line, and the body of the block.
From a quick look through the code implementation of the Indent rule, it seems as though indentCase handling is dispersed throughout the whole implementation. Would it be possible to instead just add an additional indent when opening a switch scope with indentCase enabled? That approach feels like it would reduce coupling of all the various line wrapping/indentation features significantly and lead to things composing better.
Before formatting (my preferred style)
switch blah {
case .arc(
let center,
let radius,
):
path.appendArc(...)
}
After formatting
switch blah {
case .arc(
let center,
let radius,
):
path.appendArc(...)
}
Alternative formatting output if I put a linebreak after case
If I insert a linebreak immediately after case then it gets closer to my desired formatting (although this still looks rather strange to me).
switch blah {
case
.arc(
let center,
let radius,
):
path.appendArc(...)
}
After formatting without indent-case option
switch blah {
case .arc(
let center,
let radius,
):
path.appendArc(...)
}
Configuration
--swift-version 5.10
--max-width 100
--indent-case true
--no-space-operators ...,..<
--pattern-let inline
--semicolons never
--strip-unused-args closure-only
--wrap-collections before-first
--wrap-parameters before-first
--single-line-for-each convert
--allow-partial-wrapping false
--wrap-arguments before-first
--wrap-parameters before-first
--rules blockComments,consecutiveBlankLines, \
consecutiveSpaces,consistentSwitchCaseSpacing, \
docCommentsBeforeModifiers,duplicateImports, \
lineBreakAtEndOfFile,preferKeyPath, \
singlePropertyPerLine,spaceInsideComments, \
wrapArguments, wrap, indent, preferForLoop, \
hoistPatternLet, spaceAroundOperators, \
unusedArguments, semicolons
Version
$ swiftformat --version
0.60.0
I understand that there are many different preferences, but I believe that this particular behaviour is likely not desirable to anyone so it should be changed to something nicer.
I've included an example of the formatting behaviour without
indent-case, and I would've expected that theindent-caseoption would simply indent the entire case block (which would achieve my preferred style), but instead it seems to only indent the opening case line, and the body of the block.From a quick look through the code implementation of the
Indentrule, it seems as thoughindentCasehandling is dispersed throughout the whole implementation. Would it be possible to instead just add an additional indent when opening aswitchscope withindentCaseenabled? That approach feels like it would reduce coupling of all the various line wrapping/indentation features significantly and lead to things composing better.Before formatting (my preferred style)
After formatting
Alternative formatting output if I put a linebreak after
caseIf I insert a linebreak immediately after
casethen it gets closer to my desired formatting (although this still looks rather strange to me).After formatting without
indent-caseoptionConfiguration
Version