Skip to content

Conversation

@calda
Copy link
Collaborator

@calda calda commented Sep 20, 2025

Swift 6.1 had bugs that unexpectedly disallowed trailing commas in a few places, like tuple values and generic argument lists (swiftlang/swift#81612).

This PR updates the trailingCommas rule to add trailing commas in these places with using Swift 6.2.

I found a remaining edge case in Swift 6.2 where trailing commas are still not supported in tuple values within generic argument lists. Working on landing a fix for that in Swift 6.3: swiftlang/swift-syntax#3153.

I'll release a new SwiftFormat version including this change after verifying that the Airbnb codebase compiles properly in Swift 6.2 after applying the updated trailingCommas functionality.

Comment on lines +2421 to +2452
func testTrailingCommasNotAddedToTupleTypeInGenericBracketsInSwift6_2() {
// In Swift 6.2, trailing commas are unexpectedly not supported in tuple types
// within generic arguments: https://github.com/swiftlang/swift-syntax/pull/3153
let input = """
let foo: Array<(
bar: String,
quux: String
)>
"""

let options = FormatOptions(trailingCommas: .always, swiftVersion: "6.2")
testFormatting(for: input, rule: .trailingCommas, options: options, exclude: [.typeSugar, .propertyTypes])
}

func testTrailingCommasAddedToTupleTypeInGenericBracketsInSwift6_3() {
let input = """
let foo: Array<(
bar: String,
quux: String
)>
"""

let output = """
let foo: Array<(
bar: String,
quux: String,
)>
"""

let options = FormatOptions(trailingCommas: .always, swiftVersion: "6.3")
testFormatting(for: input, output, rule: .trailingCommas, options: options, exclude: [.typeSugar, .propertyTypes])
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov
Copy link

codecov bot commented Sep 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.37%. Comparing base (47274e9) to head (c75b06c).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2211   +/-   ##
========================================
  Coverage    95.36%   95.37%           
========================================
  Files          155      155           
  Lines        29971    30033   +62     
========================================
+ Hits         28582    28644   +62     
  Misses        1389     1389           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@calda calda merged commit 43d1e12 into nicklockwood:develop Sep 20, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant