Update param wrapping rule for functions with no params#2467
Conversation
|
@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 |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Co-authored-by: calda <1811727+calda@users.noreply.github.com>
Co-authored-by: calda <1811727+calda@users.noreply.github.com>
... Implemented in 726f5d0. The fix in |
…ers (#2467) Co-authored-by: calda <1811727+calda@users.noreply.github.com>
Prevents the
wrapandwrapArgumentsrules from wrapping inside empty()of trivial function declarations — functions with no parameters, no return type, and no effects (just() {).For example, this prevents wrapping:
to either of these undesirable forms:
// 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:
Changes
Sources/FormattingHelpers.swift: Added a guard inwrapCollectionsAndArgumentsthat 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 coveringwrapParameters: .beforeFirstforfunc,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.