Swift-format rule change

Hi,

I am using swift-format

I have the following code originally:

nonisolated 
struct S {
    let greeting = "hello"
}

After swift-format is applied, it gets changed to

nonisolated 
    struct S 
{
    let greeting = "hello"
}

Questions

  1. Is it possible to change some rule to prevent this indentation of struct S?
  2. Or is there any other workaround?

Put them on the same line?

Thanks @tera
That is what I have done for now, kept it in the same line.

Reason for asking was:

  • I was annotating @MainActor in 2 separate lines, so thought it would be nice to have nonisolated in 2 lines
  • Also the examples I saw in the presentations also contained nonisolated in a separate line, in my personal preference looked nicer. This is subjective, just stating my preference.

Questions:

  • Just wondering if most keep it in the same line or have it separate lines?
  • If many tend to use it in different lines could this be considered by the swift-format team to handle such cases?

I also tend to keep important attributes such as @MainActor on the same line as the type declaration. Why? Two reasons. 1) vertical space is more valuable than horizontal. 2) When a type is large and extends beyond the visible window, Xcode shows only a single-line sticky header. Having key type information in that header is very helpful; not seeing important attributes such as @MainActor is not.

1 Like

Regardless of the desired formatting, this definitely seems like a bug, as indenting the struct line is nonsensical. I suggest you file a bug on swift-format.

1 Like

Thanks a lot @Jon_Shier

I have created an issue on GitHub nonisolated in a separate line causes next line to be indented · Issue #1260 · swiftlang/swift-format · GitHub