Skip to content

Update param wrapping rule for functions with no params#2467

Merged
calda merged 3 commits intodevelopfrom
copilot/update-param-wrapping-rule
Mar 19, 2026
Merged

Update param wrapping rule for functions with no params#2467
calda merged 3 commits intodevelopfrom
copilot/update-param-wrapping-rule

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 19, 2026

Prevents the wrap and wrapArguments rules from wrapping inside empty () of trivial function declarations — functions with no parameters, no return type, and no effects (just () {).

For example, this prevents wrapping:

func longFunctionNameBeyondWrappingLimit() {
}

to either of these undesirable forms:

// Previously possible — now prevented
func longFunctionNameBeyondWrappingLimit(
) {
}
// Also prevented for trivial () { functions
func longFunctionNameBeyondWrappingLimit()
{
}

The fix also actively unwraps already-wrapped empty parameter lists for trivial functions back to () {.

Functions with return types, generics, effects, etc. are not affected — wrapping is still allowed for those cases:

// This can still wrap as before
func foo() -> Int {}

Changes

  • Sources/FormattingHelpers.swift: Added a guard in wrapCollectionsAndArguments that skips wrapping for empty parameter lists when the function is trivial (no return type, effects, generics — just () {). Also unwraps any already-wrapped empty parens in that case.
  • Tests/Rules/WrapTests.swift: Added 3 tests covering no-wrap for multi-line and single-line functions, and unwrapping of already-wrapped empty parens.
  • Tests/Rules/WrapArgumentsTests.swift: Added 3 tests covering wrapParameters: .beforeFirst for func, init, and unwrapping of already-wrapped empty parens.

All 5471 existing tests pass with the changes.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI requested a review from calda March 19, 2026 16:14
Copilot stopped work on behalf of calda due to an error March 19, 2026 16:14
@calda
Copy link
Copy Markdown
Collaborator

calda commented Mar 19, 2026

@copilot, also ensure we don't wrap it to:

func `long function name beyond wrapping limit()
{
}

It should be preserved as-is.

If it has a return type, generics, params, etc, it's fine to wrap. Just don't wrap a trivial () { function like that.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.28%. Comparing base (4bab950) to head (3af77a9).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2467      +/-   ##
===========================================
- Coverage    95.28%   95.28%   -0.01%     
===========================================
  Files          165      165              
  Lines        25230    25243      +13     
===========================================
+ Hits         24041    24052      +11     
- Misses        1189     1191       +2     

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

Copilot AI and others added 2 commits March 19, 2026 16:44
Co-authored-by: calda <1811727+calda@users.noreply.github.com>
Co-authored-by: calda <1811727+calda@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 19, 2026

@copilot, also ensure we don't wrap it to:

...

Implemented in 726f5d0. The fix in wrapCollectionsAndArguments skips wrapping for empty parameter lists where the function has no return type, effects, or other complexity — just a trivial () {. It also actively unwraps any already-wrapped empty parens in that case. Functions with return types (func foo() -> Int {}), effects, generics, etc. are still allowed to wrap as before.

Copilot AI changed the title [WIP] Update param wrapping rule for functions with no params Update param wrapping rule for functions with no params Mar 19, 2026
@calda calda marked this pull request as ready for review March 19, 2026 17:03
@calda calda merged commit c7a265b into develop Mar 19, 2026
17 of 18 checks passed
@calda calda deleted the copilot/update-param-wrapping-rule branch March 19, 2026 17:04
calda added a commit that referenced this pull request Apr 11, 2026
…ers (#2467)

Co-authored-by: calda <1811727+calda@users.noreply.github.com>
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.

2 participants