nicklockwood / SwiftFormat

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

False positive with `spaceAroundBrackets` for consuming or borrowing array parameter #1656

Closed Jnosh closed 2 months ago

Jnosh commented 3 months ago

The following reports a violation of the spaceAroundBrackets rule:

func foo(arg: consuming [String]) {
  // ...
}

Same with borrowing or when using the non-shorthand Array<...> syntax.

swiftformat expects the following instead:

func foo(arg: consuming[String]) {
  // ...
}

swiftformat: 0.53.5

Jnosh commented 3 months ago

I just noticed another similar issue when using the isolated keyword:

// warning: (spaceAroundParens) Add or remove space around parentheses.
func foo(isolation: isolated (any Actor)) {
    // ...
}

Here spaceAroundParens is triggered where SwiftFormat wants to remove the space between isolated and the following parentheses. I'm just adding it here since it's a very similar issue but feel free to let me know if I should open a separate issue.

As written above, the parentheses are redundant anyway and can just be removed but this will become relevant with SE-420 which allows isolated to take an optional argument, e.g. (any Actor)? where the parentheses become necessary.

nicklockwood commented 3 months ago

Thanks for reporting this, I'll get it fixed

nicklockwood commented 2 months ago

@Jnosh fixed in 0.53.6

Jnosh commented 2 months ago

Thank you, I tried the new release and it's working perfectly.