Skip to content

Add support of trailing commas in all cases containing round parentheses in Swift 6.1 #2008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 13, 2025

Conversation

kfamyn
Copy link
Contributor

@kfamyn kfamyn commented Apr 13, 2025

Overview

This PR adds support of trailing commas in all cases containing round parentheses () in Swift 6.1

Implemented earlier

Trailing commas were already supported in:

  • Multi-line collections
  • Parameter or argument lists
  • Enum cases with associated values

New features

Trailing commas are now added (or removed) for multi-line lists in the following contexts:

  • Array and dictionary literals
  • Function and initializer parameters and arguments
  • Enum case associated values
  • Tuple literals, including in return, switch, case let, let
  • Parenthesized single expressions (e.g., throw (error,), if (true,), guard (true,), while (true,))
  • Attribute arguments (e.g. @Attribute(...))
  • Macro arguments (e.g. #macro(...))
  • String interpolation expressions (when custom interpolation methods allow multiple arguments)

Trailing commas are not added in:

  • Empty parentheses ()
  • Type annotations (e.g. let x: (Int, String))

Future plans

I'm planning to add trailing commas in the following contexts in the next PR:

  • Subscripts, including key path subscripts
  • Closure capture lists
  • Generic parameters

In addition to this, I'm planning to debug and fix failing tests in TrailingCommasTests

Testing info

To test String interpolation, use this extension:

extension String.StringInterpolation {
    
    mutating func appendInterpolation(_ a: Int, _ b: Int) {
        appendLiteral("\(a)\(b)")
    }
}

@kfamyn kfamyn changed the title Develop Add support of trailing commas in all cases containing round parentheses in Swift 6.1 Apr 13, 2025
Copy link

codecov bot commented Apr 13, 2025

Codecov Report

Attention: Patch coverage is 93.93939% with 2 lines in your changes missing coverage. Please review.

Project coverage is 95.79%. Comparing base (eb81f2f) to head (aab424f).
Report is 4 commits behind head on develop.

Files with missing lines Patch % Lines
Sources/Rules/TrailingCommas.swift 93.93% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2008      +/-   ##
===========================================
+ Coverage    95.51%   95.79%   +0.27%     
===========================================
  Files          141      141              
  Lines        25982    26010      +28     
===========================================
+ Hits         24817    24916      +99     
+ Misses        1165     1094      -71     

☔ 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.

Copy link
Collaborator

@calda calda left a comment

Choose a reason for hiding this comment

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

Thanks!

@calda calda merged commit f89b831 into nicklockwood:develop Apr 13, 2025
8 of 11 checks passed
calda pushed a commit to calda/SwiftFormat that referenced this pull request Apr 30, 2025
calda pushed a commit that referenced this pull request Apr 30, 2025
calda pushed a commit that referenced this pull request Apr 30, 2025
calda pushed a commit to calda/SwiftFormat that referenced this pull request May 2, 2025
@KonDouvris
Copy link

Hello @nicklockwood ! Is this released in the latest 0.55.6 version?

@nicklockwood
Copy link
Owner

@KonDouvris no, 0.55.6 is just bug fixes. This will be included in the 0.56 release

calda pushed a commit that referenced this pull request May 13, 2025
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.

4 participants