Swift-format configuration

Hi,

Overview

  • I just started trying out swift-format using Xcode 26 (Control Shift I)

Questions

  1. Why does xcrun swift-format dump-configuration show configurations different from what I notice in Xcode?
Property swift-format dump-configuration Xcode Behaviour
lineLength 100 80
indentation 2 4
  1. Is it because the swift-format dump-configuration is overridden by Xcode's Settings?
  • Settings > Editing > Completion > Reformat code at column - 80
  • Settings > Editing > Indentation > Indent width - 4 spaces
  1. Is it possible to use the Xcode defaults and add only the overrides to .swift-format file?
  • I can set Reformat code at column to 100 in Xcode
  • I like the Xcode defaults, all I need is "spacesAroundRangeFormationOperators" : true
  • However when I add only spacesAroundRangeFormationOperators in .swift-format, it seems to make the indentation to 2

swift-format uses this file based approach to its configuration which is very different to what Xcode uses for its settings, so while it might feel odd the two don't match it's not too surprising.

What I'd do is xcrun swift-format dump-configuration, move that file into .swift-format file where swift-format could find it (e.g. near the project file or in one of the parent folders (a reasonable choice is source control repository root folder), and modify it according to your needs (changing lineLength / indentation / etc to what you want them to be).

1 Like

Thanks a lot @tera

That is what I have done too placed it in the project's root folder.

Also I think swift format is equivalent to xcrun swift-format