nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.67k stars 623 forks source link

Update wrapAttributes "complex attributes" logic to exclude attributes with a single unnamed argument #1595

Closed calda closed 7 months ago

calda commented 7 months ago

This PR updates the wrapAttributes "complex attributes" logic to exclude attributes with a single unnamed argument.

This removes the need to special-case the @Environment attribute, which we specifically don't want to consider "complex". Since this doesn't require special casing any particular attribute, it generalizes to other similar attributes like @AppStorage from SwiftUI and @Dependency from TCA.

These are no longer considered complex, so can be configured to not wrap using --storedvarattrs same-line:

@Environment(\.controlPanelStyle) private var controlPanelStyle
@Dependency(\.controlsService) private var controlsService
@AppStorage("ControlsConfig") private var controlsConfig: ControlConfiguration

These examples are all still considered complex, so can be configured to always wrap using --complexattrs prev-line:

@AppStorage("ControlsConfig", store: myCustomUserDefaults)
private var controlsConfig: ControlConfiguration

@Tweak(name: "Aspect ratio")
private var aspectRatio = AspectRatio.stretch

@available(*, unavailable)
var saturn5Builder: Saturn5Builder

@available(*, unavailable, message: "No longer in production")
var saturn5Builder: Saturn5Builder
codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (a73bd38) 95.07% compared to head (1da8235) 95.07%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #1595 +/- ## =========================================== - Coverage 95.07% 95.07% -0.01% =========================================== Files 20 20 Lines 22084 22112 +28 =========================================== + Hits 20996 21022 +26 - Misses 1088 1090 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.