nicklockwood / SwiftFormat

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

Improve attribute handling in opaqueGenericParameters rule #1713

Closed calda closed 4 weeks ago

calda commented 1 month ago

This PR improves attribute handling in the opaqueGenericParameters rule.

To fix #1684, https://github.com/nicklockwood/SwiftFormat/commit/383fd4813c7fb45e4e996242b6c7c919133f5dc1 made it so the opaqueGenericParameters was disabled for all functions with attributes. However, in most cases attributes don't cause any issues. For example:

@MyResultBuilder
func foo<T: Foo, U: Bar>(foo: T, bar: U) -> MyResult {
    foo
    bar
}

@MyFunctionBodyMacro(withArgument: true)
func foo<T: Foo, U: Bar>(foo: T, bar: U) {
    print(foo, bar)
}

This PR tweaks the existing fix to check the tokens of the attributes, and whether or not they reference any of the generic arguments. #1684 remains fixed, and the above examples are now updated as expected:

@MyResultBuilder
func foo(foo: some Foo, bar: some Bar) -> MyResult {
    foo
    bar
}

@MyFunctionBodyMacro(withArgument: true)
func foo(foo: some Foo, bar: some Bar) {
    print(foo, bar)
}
codecov[bot] commented 1 month ago

Codecov Report

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

Project coverage is 95.14%. Comparing base (f487996) to head (91bf6e3).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #1713 +/- ## ======================================== Coverage 95.13% 95.14% ======================================== Files 20 20 Lines 23124 23130 +6 ======================================== + Hits 21998 22006 +8 + Misses 1126 1124 -2 ```

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