mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
Don't exclude closures from braces rule
This commit is contained in:
@@ -1418,9 +1418,6 @@ public struct _FormatRules {
|
||||
formatter.removeToken(at: closingBraceIndex - 1)
|
||||
}
|
||||
}
|
||||
guard !formatter.isStartOfClosure(at: i) else {
|
||||
return
|
||||
}
|
||||
if formatter.options.allmanBraces {
|
||||
// Implement Allman-style braces, where opening brace appears on the next line
|
||||
switch formatter.last(.nonSpace, before: i) ?? .space("") {
|
||||
|
||||
+7
-31
@@ -2420,7 +2420,8 @@ class RulesTests: XCTestCase {
|
||||
"""
|
||||
|
||||
let options = FormatOptions(wrapArguments: .disabled, closingParenOnSameLine: true)
|
||||
testFormatting(for: input, rule: FormatRules.indent, options: options)
|
||||
testFormatting(for: input, rule: FormatRules.indent, options: options,
|
||||
exclude: ["braces"])
|
||||
}
|
||||
|
||||
func testSingleIndentTrailingClosureBodyOfShortMethod() {
|
||||
@@ -2514,7 +2515,8 @@ class RulesTests: XCTestCase {
|
||||
}
|
||||
"""
|
||||
let options = FormatOptions(xcodeIndentation: true)
|
||||
testFormatting(for: input, output, rule: FormatRules.indent, options: options)
|
||||
testFormatting(for: input, output, rule: FormatRules.indent, options: options,
|
||||
exclude: ["braces"])
|
||||
}
|
||||
|
||||
func testWrappedMultilineStringOnNewLineWithXcodeIndentation() {
|
||||
@@ -3414,31 +3416,6 @@ class RulesTests: XCTestCase {
|
||||
testFormatting(for: input, rule: FormatRules.braces)
|
||||
}
|
||||
|
||||
func testKnRBracesIgnoresClosure() {
|
||||
let input = """
|
||||
let foo =
|
||||
{ bar in
|
||||
print(bar)
|
||||
}
|
||||
"""
|
||||
testFormatting(for: input, rule: FormatRules.braces)
|
||||
}
|
||||
|
||||
func testUnbalancedClosingClosureBraceCorrected() {
|
||||
let input = """
|
||||
let foo =
|
||||
{ bar in
|
||||
print(bar) }
|
||||
"""
|
||||
let output = """
|
||||
let foo =
|
||||
{ bar in
|
||||
print(bar)
|
||||
}
|
||||
"""
|
||||
testFormatting(for: input, output, rule: FormatRules.braces)
|
||||
}
|
||||
|
||||
func testAllmanComputedPropertyBracesConverted() {
|
||||
let input = """
|
||||
var foo: Int
|
||||
@@ -8105,7 +8082,7 @@ class RulesTests: XCTestCase {
|
||||
true
|
||||
}
|
||||
"""
|
||||
let options = FormatOptions(maxWidth: 20)
|
||||
let options = FormatOptions(allmanBraces: true, maxWidth: 20)
|
||||
testFormatting(for: input, [output, output2], rules: [FormatRules.wrap], options: options)
|
||||
}
|
||||
|
||||
@@ -8124,7 +8101,7 @@ class RulesTests: XCTestCase {
|
||||
bar
|
||||
}
|
||||
"""
|
||||
let options = FormatOptions(maxWidth: 20)
|
||||
let options = FormatOptions(allmanBraces: true, maxWidth: 20)
|
||||
testFormatting(for: input, [output, output2], rules: [FormatRules.wrap], options: options)
|
||||
}
|
||||
|
||||
@@ -8743,8 +8720,7 @@ class RulesTests: XCTestCase {
|
||||
var mathFunction: (Int,
|
||||
Int,
|
||||
String)
|
||||
-> Int =
|
||||
{ _, _, _ in
|
||||
-> Int = { _, _, _ in
|
||||
0
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -813,7 +813,6 @@ extension RulesTests {
|
||||
("testKnRBracesAfterMultilineComment", testKnRBracesAfterMultilineComment),
|
||||
("testKnRBracesAfterMultilineComment2", testKnRBracesAfterMultilineComment2),
|
||||
("testKnRBracesAreConverted", testKnRBracesAreConverted),
|
||||
("testKnRBracesIgnoresClosure", testKnRBracesIgnoresClosure),
|
||||
("testKnRClosingBraceWrapped", testKnRClosingBraceWrapped),
|
||||
("testKnRExtraSpaceNotAddedBeforeBrace", testKnRExtraSpaceNotAddedBeforeBrace),
|
||||
("testKnRInlineBracesNotWrapped", testKnRInlineBracesNotWrapped),
|
||||
@@ -1721,7 +1720,6 @@ extension RulesTests {
|
||||
("testTypeAttributeStaysWrapped", testTypeAttributeStaysWrapped),
|
||||
("testTypedClosureArgumentNotUnwrapped", testTypedClosureArgumentNotUnwrapped),
|
||||
("testTypedMultipleClosureArgumentNotUnwrapped", testTypedMultipleClosureArgumentNotUnwrapped),
|
||||
("testUnbalancedClosingClosureBraceCorrected", testUnbalancedClosingClosureBraceCorrected),
|
||||
("testUnhoistCaseLet", testUnhoistCaseLet),
|
||||
("testUnhoistCaseVar", testUnhoistCaseVar),
|
||||
("testUnhoistCatchLet", testUnhoistCatchLet),
|
||||
|
||||
Reference in New Issue
Block a user