Skip to content

Commit

Permalink
Remove check for prioritizeKeepingFunctionOutputTogether on enum decl.
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnhyam committed Apr 29, 2024
1 parent 58c2ef5 commit 2dd68a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 0 additions & 8 deletions Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1350,14 +1350,6 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
}

override func visit(_ node: EnumCaseParameterClauseSyntax) -> SyntaxVisitorContinueKind {
// Prioritize keeping ") throws -> <return_type>" together. We can only do this if the function
// has arguments.
if !node.parameters.isEmpty && config.prioritizeKeepingFunctionOutputTogether {
// Due to visitation order, this .open corresponds to a .close added in FunctionDeclSyntax
// or SubscriptDeclSyntax.
before(node.rightParen, tokens: .open)
}

return .visitChildren
}

Expand Down
12 changes: 12 additions & 0 deletions Tests/SwiftFormatTests/PrettyPrint/EnumDeclTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,16 @@ final class EnumDeclTests: PrettyPrintTestCase {
let input = "enum Foo { var bar: Int }"
assertPrettyPrintEqual(input: input, expected: input + "\n", linelength: 50)
}

func testEnumWithPrioritizeKeepingFunctionOutputTogetherFlag() {
let input = """
enum Error {
case alreadyOpen(Int)
}
"""
var config = Configuration.forTesting
config.prioritizeKeepingFunctionOutputTogether = true
assertPrettyPrintEqual(input: input, expected: input, linelength: 50, configuration: config)
}
}

0 comments on commit 2dd68a0

Please sign in to comment.