nicklockwood / SwiftFormat

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

Inconsistent await tuple formatting between Xcode extension and command-line #1224

Closed simondelphia closed 2 years ago

simondelphia commented 2 years ago

I am getting different behaviour for this between the command line and the Xcode extension.

have a .swiftformat file in my repo, and I opened it in the "SwiftFormat for Xcode" app, and I made sure the command line and the app have the same version (0.49.13).

EDIT: Still a problem in 0.49.14

When formatting a tuple with an await inside Xcode it makes it await ( and the command line makes it await(

My .swiftformat file has --swiftversion 5.6 and I'm on Xcode 13.4.1 (13F100). SwiftFormat for Xcode is also showing Swift 5.6.

nicklockwood commented 2 years ago

@simondelphia can you share your .swiftformat file and a source example? I'm not able to reproduce this. If I have a file containing:

let foo = await (bar, baz)

And a .swiftformat file with just:

--swiftversion 5.6

And I run swiftformat . inside that directory, I get no changes. If I reduce the version to 5.4 then it removes the space after await.

If I try it with the Xcode plugin I get the same behavior. This all seems as expected.

simondelphia commented 2 years ago

Hm yea I copied my swiftformat file into a folder with a new blank project and put in a couple lines with await (…, …) in one of its Swift files and you're right it's working there, just not in my actual project. Even if I copy an entire file from my project into a new folder with the .swiftformat file and run swiftformat . it works properly.

Double-checked the Swift version in my project and it is definitely 5.6.

I copied a Swift file with an await( to the root of my project and the command line worked properly, but if I move it into the folder with my project file then it doesn't work. Presumably something is being inferred from the project file but what would it be?

here's the content of the .swiftformat file:

# file options

--exclude build,fastlane,SourcePackages,vendor

# format options

--allman false
--binarygrouping 4,8
--commas always
--comments indent
--decimalgrouping 3,6
--elseposition same-line
--empty void
--exponentcase lowercase
--exponentgrouping disabled
--fractiongrouping disabled
--header ignore
--hexgrouping 4,8
--hexliteralcase uppercase
--ifdef indent
--indent 2
--indentcase false
--importgrouping testable-bottom
--linebreaks lf
--maxwidth none
--octalgrouping 4,8
--operatorfunc spaced
--patternlet hoist
--ranges no-space
--self remove
--semicolons never
--stripunusedargs always
--swiftversion 5.6
--trimwhitespace always
--wraparguments preserve
--wrapcollections preserve
--xcodeindentation disabled

# rules

--enable isEmpty
--minversion 0.49
nicklockwood commented 2 years ago

Do you have a .swift-version file in your project directory?

Also, when you run swiftformat from the terminal, does list any other Reading config file at ... paths?

simondelphia commented 2 years ago

Yes I have .swift-version with 5.6.1 in it — the patch is probably unnecessary, but that seems like it shouldn't matter?

I also tried it with the .swift-version copied over to my test folder and it worked fine

When I run swiftformat from the terminal it only lists Reading config file at ... once, for the expected file

simondelphia commented 2 years ago

I also just tried copying my whole project file into a separate folder with my config file and swift version file and it worked there. So maybe the project file isn't the issue.

simondelphia commented 2 years ago

Oh wow there's another (redundant) .swift-version file in a subfolder with 5.3 that I did not notice. Have no idea why that's there, must be left over from a long time ago. My bad @nicklockwood, thanks for the assist!

😅

simondelphia commented 2 years ago

Might be helpful if the command line logs noted all the swift-version files it was referencing like how it does it for the config files?