Skip to content

Commit

Permalink
Unwrap multiline statement braces if rule disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Mar 6, 2022
1 parent 363b972 commit f985667
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/Rules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1956,8 +1956,8 @@ public struct _FormatRules {
}

// Avoid conflicts with wrapMultilineStatementBraces
// TODO: find a better solution for this
if let keywordIndex =
let ruleName = FormatRules.wrapMultilineStatementBraces.name
if formatter.options.enabledRules.contains(ruleName), let keywordIndex =
formatter.indexOfLastSignificantKeyword(at: prevIndex + 1, excluding: ["where"]),
case let .keyword(keyword) = formatter.tokens[keywordIndex],
["if", "for", "guard", "while", "switch", "func", "init", "subscript",
Expand Down
31 changes: 31 additions & 0 deletions Tests/RulesTests+Braces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,37 @@ class BracesTests: RulesTests {
testFormatting(for: input, output, rule: FormatRules.braces)
}

func testBraceUnwrappedIfWrapMultilineStatementBracesRuleDisabled() {
let input = """
if let foo = bar,
let baz = quux
{
return nil
}
"""
let output = """
if let foo = bar,
let baz = quux {
return nil
}
"""
testFormatting(for: input, output, rule: FormatRules.braces,
exclude: ["wrapMultilineStatementBraces"])
}

func testBraceNotUnwrappedIfWrapMultilineStatementBracesRuleDisabled() {
let input = """
if let foo = bar,
let baz = quux
{
return nil
}
"""
testFormatting(for: input, rules: [
FormatRules.braces, FormatRules.wrapMultilineStatementBraces,
])
}

// allman style

func testKnRBracesAreConverted() {
Expand Down

0 comments on commit f985667

Please sign in to comment.