Skip to content

Commit 63d4dcc

Browse files
authored
Merge pull request swiftlang#182 from dabelknap/assorted-fixes
Assorted Fixes
2 parents 9f9398b + 2b4af9b commit 63d4dcc

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

Diff for: Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
117117

118118
override func visit(_ node: TupleElementSyntax) {
119119
before(node.firstToken, tokens: .open)
120+
after(node.colon, tokens: .break)
120121
after(node.lastToken, tokens: .close)
121122
super.visit(node)
122123
}
@@ -834,7 +835,11 @@ private final class TokenStreamCreator: SyntaxVisitor {
834835
node.genericWhereClause?.firstToken,
835836
tokens: .break, .open(.inconsistent, 0), .break(size: 0), .open(.consistent, 0)
836837
)
837-
after(node.genericWhereClause?.lastToken, tokens: .break, .close, .close)
838+
if node.body != nil {
839+
after(node.genericWhereClause?.lastToken, tokens: .break, .close, .close)
840+
} else {
841+
after(node.genericWhereClause?.lastToken, tokens: .close, .close)
842+
}
838843

839844
if let body = node.body {
840845
if node.genericWhereClause == nil {

Diff for: Sources/generate-pipeline/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let outputFile = sourcesDir.appendingPathComponent("swift-format")
2222
let fm = FileManager.default
2323

2424
// These rules will not be added to the pipeline
25-
let suppressRules = ["UseEarlyExits"]
25+
let suppressRules = ["UseEarlyExits", "UseWhereClausesInForLoops"]
2626

2727
enum PassKind {
2828
case format, lint, file

Diff for: Sources/swift-format/PopulatePipeline.swift

-6
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,6 @@ func populate(_ pipeline: Pipeline) {
234234
VariableDeclSyntax.self
235235
)
236236

237-
pipeline.addFormatter(
238-
UseWhereClausesInForLoops.self,
239-
for:
240-
ForInStmtSyntax.self
241-
)
242-
243237
/// MARK: Linting Passes
244238

245239
pipeline.addLinter(

Diff for: Tests/SwiftFormatPrettyPrintTests/FunctionDeclTests.swift

+30
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,36 @@ public class FunctionDeclTests: PrettyPrintTestCase {
301301
assertPrettyPrintEqual(input: input, expected: expected, linelength: 50)
302302
}
303303

304+
public func testBodilessFunctionDecl() {
305+
let input =
306+
"""
307+
func myFun()
308+
309+
func myFun(arg1: Int)
310+
311+
func myFun() -> Int
312+
313+
func myFun<T>(arg1: Int)
314+
315+
func myFun<T>(arg1: Int) where T: S
316+
"""
317+
318+
let expected =
319+
"""
320+
func myFun()
321+
322+
func myFun(arg1: Int)
323+
324+
func myFun() -> Int
325+
326+
func myFun<T>(arg1: Int)
327+
328+
func myFun<T>(arg1: Int) where T: S
329+
330+
"""
331+
332+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 50)
333+
}
304334

305335
public func testFunctionFullWrap() {
306336
let input =

Diff for: Tests/SwiftFormatPrettyPrintTests/TupleDeclTests.swift

+17
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,21 @@ public class TupleDeclTests: PrettyPrintTestCase {
4949

5050
assertPrettyPrintEqual(input: input, expected: expected, linelength: 37)
5151
}
52+
53+
public func testLabeledTuples() {
54+
let input =
55+
"""
56+
let a = (A: var1, B: var2)
57+
var b: (A: Int, B: Double)
58+
"""
59+
60+
let expected =
61+
"""
62+
let a = (A: var1, B: var2)
63+
var b: (A: Int, B: Double)
64+
65+
"""
66+
67+
assertPrettyPrintEqual(input: input, expected: expected, linelength: 30)
68+
}
5269
}

0 commit comments

Comments
 (0)