Disable [AddLines], etc in swift-format

How do I disable those "globally" in swift-format?

[Spacing] add 1 space
[AddLines] add 1 line break
[Indentation] unindent by 2 spaces
[TrailingWhitespace] remove trailing whitespace
[Indentation] replace leading whitespace with 4 spaces

I set all settings in "rules" dictionary of ".swift-format" file to false, but still seeing the above.

Hm, how exactly you're doing it? Haven't seen rules like AddLines. :thinking:

I've used documentation and swift-nio repo format is a good example, haven't had any issues.

Nothing out of ordinary:

Indentation warning is particularly annoying: Xcode comments out large blocks by placing // at the start of each line.

1 Like

Tried to ignore TrailingWhitespace / Indentation with:

// swift-format-ignore: TrailingWhitespace, Indentation

but that seems to (silently) ignoring them. I could put a non specific // swift-format-ignore before the node but then all formatting issues are ignored, which is not ideal.


Specific example which I don't know how to deal with properly using swift-format:

#if someCompilationFlag
// lot's of code deliberately unindented
#else
// lot's of code deliberately unindented
#endif

I want those fragments of code to stay unindented. For example I could add/remove #if/#end if brackets freely and don't want large chunks of code to be indented / un-indented and cause a massive change in the commit.

I could put // swift-format-ignore before the #if someCompilationFlag, but that would ignore all formatting issues in the code, something I'd like to avoid.

Even if this worked:

// swift-format-ignore: Indentation
#if someCompilationFlag
// do not want "indentation wrong" warning about foo, bar, baz

func foo() {
    ...
}

func bar() {
    ...
}

func baz() {
let x = 1 // but (obviously) do want formatting warning here
}
...

(and it doesn't work) I'd still want indentation warnings for improper formatting of internal nodes.

Found a solution to this particular issue:

  "indentConditionalCompilationBlocks" : false,

in .swift-format file does the trick.