Skip to content

Add a swift-format configuration file #9005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": 1,
"lineLength": 10000,
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with this; we should not enforce a line length.

"indentation": {
Copy link
Contributor Author

@bkhouri bkhouri Aug 8, 2025

Choose a reason for hiding this comment

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

suggestion: I haven't read the documentation, but based on the setting name, we should consider "multiElementCollectionTrailingCommas" : true,.

Copy link
Contributor

Choose a reason for hiding this comment

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

That corresponds to:

[
    "a",
    "b"
]

vs

[
    "a",
    "b",
]

Support for the latter was added to Swift some time ago, the argument being that it helps reduce the SCM diff as new lines are added to the bottom.

I'd be fine with enabling that rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want the latter :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also want

[1, 3]

to format to

[
    1,
    3,
]

"spaces": 4
},
"lineBreakBeforeEachArgument": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

This rule feels a little too opinionated to me, not sure if anyone else has an opinion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this option helps make the diff ever-so-slightly cleaner to read.

Copy link
Contributor

Choose a reason for hiding this comment

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

This would result in a pretty huge diff. While I agree it can enhance readability in some cases, I'm not sure we should make the jump right away. I'd omit this for now and maybe we should have a wider discussion first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to get to the following

func foo(a: Int, b: String) {
}

to

func foo(
    a: Int,
    b: String,
) {
}

"rules": {
},
Copy link
Contributor Author

@bkhouri bkhouri Aug 8, 2025

Choose a reason for hiding this comment

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

suggestion: I haven't read the documentation ,but based on the setting name, we should consider the following, eventually:

  "rules" : {
    "AllPublicDeclarationsHaveDocumentation" : false,
  }

Copy link
Contributor

Choose a reason for hiding this comment

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

Good to strive towards, but we should not add that immediately as I think for SwiftPM in particular there's a lot which is public but which maybe shouldn't be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100% agree :). Something to consider for the future.

"tabWidth": 4
}