mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
Fix indent regression in xcode indent mode
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// swiftformat:disable blankLinesBetweenScopes
|
||||
// swiftformat:disable wrapMultilineStatementBraces
|
||||
// swiftformat:options --commas false
|
||||
// swiftformat:options --xcodeindentation enabled
|
||||
// swiftformat:options --extensionacl on-declarations
|
||||
// swiftformat:options --modifierorder public,override
|
||||
// swiftformat:options --patternlet inline
|
||||
// swiftformat:options --trimwhitespace nonblank-lines
|
||||
|
||||
func testing() {
|
||||
firstly {
|
||||
doSomething()
|
||||
}
|
||||
// then do something else
|
||||
.then {
|
||||
doSomethingElse()
|
||||
}
|
||||
// convert the thing
|
||||
.map {
|
||||
transform($0)
|
||||
}
|
||||
}
|
||||
+18
-4
@@ -1635,10 +1635,24 @@ public struct _FormatRules {
|
||||
linewrapStack[linewrapStack.count - 1] = false
|
||||
indent = indentStack.last!
|
||||
} else {
|
||||
let shouldIndentLeadingDotStatement = formatter.options.xcodeIndentation
|
||||
|| (formatter.startOfConditionalStatement(at: i) != nil
|
||||
&& formatter.options.wrapConditions == .beforeFirst)
|
||||
|
||||
let shouldIndentLeadingDotStatement: Bool
|
||||
if formatter.options.xcodeIndentation {
|
||||
if let prevIndex = formatter.index(of: .nonSpaceOrCommentOrLinebreak, before: i),
|
||||
formatter.token(at: formatter.startOfLine(
|
||||
at: prevIndex, excludingIndent: true
|
||||
)) == .endOfScope("}"),
|
||||
formatter.index(of: .linebreak, in: prevIndex + 1 ..< i) != nil
|
||||
{
|
||||
shouldIndentLeadingDotStatement = false
|
||||
} else {
|
||||
shouldIndentLeadingDotStatement = true
|
||||
}
|
||||
} else {
|
||||
shouldIndentLeadingDotStatement = (
|
||||
formatter.startOfConditionalStatement(at: i) != nil
|
||||
&& formatter.options.wrapConditions == .beforeFirst
|
||||
)
|
||||
}
|
||||
if shouldIndentLeadingDotStatement,
|
||||
formatter.next(.nonSpace, after: i) == .operator(".", .infix),
|
||||
let prevIndex = formatter.index(of: .nonSpaceOrCommentOrLinebreak, before: i),
|
||||
|
||||
@@ -1790,6 +1790,20 @@ class IndentTests: RulesTests {
|
||||
testFormatting(for: input, rule: FormatRules.indent, options: options)
|
||||
}
|
||||
|
||||
func testCommentSeparatedChainedFunctionAfterBraceWithXcodeIndentation() {
|
||||
let input = """
|
||||
func foo() {
|
||||
bar {
|
||||
doSomething()
|
||||
}
|
||||
// baz
|
||||
.baz()
|
||||
}
|
||||
"""
|
||||
let options = FormatOptions(xcodeIndentation: true)
|
||||
testFormatting(for: input, rule: FormatRules.indent, options: options)
|
||||
}
|
||||
|
||||
func testChainedFunctionsInPropertySetterOnNewLineWithXcodeIndentation() {
|
||||
let input = """
|
||||
private let foo =
|
||||
|
||||
Reference in New Issue
Block a user