nicklockwood / SwiftFormat

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

`swiftformat:sort` does not work on `extension` #1622

Closed domkm closed 4 months ago

domkm commented 5 months ago

// swiftformat:sort before extension does not sort declarations inside the extension.

calda commented 4 months ago

I think what must be going on is:

  1. You have both the organizeDeclarations and sortDeclarations rules enabled. When this is the case, sortDeclarations would never attempt to sort a declaration body, since that could conflict with organizeDeclarations (which implements its own sorting support)
  2. Your organizeTypes option excludes extension (the default value is class,actor,struct,enum). This made it so the organizeTypes rule didn't run on extensions. So there was no rule that would attempt to sort this declaration.

https://github.com/nicklockwood/SwiftFormat/pull/1628 fixes this so that the sortDeclarations will still sort the body of any declaration type excluded from organizeDeclarations via the organizeTypes option.

domkm commented 4 months ago

Thanks for fixing this!

I did have both organizeDeclarations and sortDeclarations enabled. However, I was using --organizetypes class,actor,struct,enum,extension,protocol so I thought it would both organize and sort within extensions.

calda commented 4 months ago

Is your issue fixed in 0.53.3? If not can you share more details to help me reproduce the issue (sharing a test case with a standalone swift file that reproduces the issue when running a specific SwiftFormat command)?

nicklockwood commented 4 months ago

@domkm I'm assuming this is fixed. Feel free to reopen if not