Skip to content

Comments

Enforce formatting in CI#45

Draft
tothambrus11 wants to merge 3 commits intomainfrom
swift-format
Draft

Enforce formatting in CI#45
tothambrus11 wants to merge 3 commits intomainfrom
swift-format

Conversation

@tothambrus11
Copy link
Member

Added a CI step to enforce formatting within the repository, and the scripts format.sh and lint.sh.

@kyouko-taiga
Copy link
Collaborator

kyouko-taiga commented Feb 22, 2026

We should discuss the addition of swift-format in a team meeting. I understand it is highly desirable for several contributors to have a tool enforcing code style automatically but I find many of swift-format's choices highly questionable and poorly interoperable with the way Xcode works.

@tothambrus11
Copy link
Member Author

tothambrus11 commented Feb 22, 2026

Alright, you can check out the reformatting changes. Some of them I also don't think are improvements, so we can look into if we can fix them with customization options, and we can discuss how to proceed in the next meeting.

@tothambrus11
Copy link
Member Author

How does Xcode work with regards to formatting? Doesn't it also use the toolchain's built-in swift-format?

Comment on lines +180 to +182
else {
throw expected("annotation argument")
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the original version was fine.

Comment on lines +427 to 430
let members =
self.next(is: .leftBrace)
? try parseTypeBody(in: &file, accepting: \.isValidStructMember)
: nil
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is not an improvement

@kyouko-taiga
Copy link
Collaborator

How does Xcode work with regards to formatting? Doesn't it also use the toolchain's built-in swift-format?

It can be set up with a post-build action. But I would not mind that much having to run some command in my terminal once in a while. My biggest complain is that Xcode has ways to automatically form certain things that swift-format will keep undoing. That is frustrating. On top of that, I personally prefer Xcode's styling over swift-format, which in places is IMO objectively worse (as you have noted in a few places).

Here are a couple of things that I think are very annoying with swift-format. That's not an exhaustive list it covers the biggest issues I can think on top of my head:

  • Forcing newline after a . if the expression unless the whole expression fits the maximum width. Example of rejected code:
let x = foo.bar(
  a: something + that + is + very + long)
  • Forcing newlines before any infix operator. You have shown examples.

  • Forcing very specific alignment for multi-line if/guard statements. That one is really annoying because it is Xcode's default, which I incidentally find much better than swift-format. Example of rejected code:

if let x = foo,
   let y = bar
{ ham(x, y) }

In addition, there are other things I have applied consistently throughout thousands of lines that swift-format is unable to enforce by itself, like adding spaces before and after the first and last member of a type declaration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants