Swift Code Formatter#

Noctule provides a native code formatter and also integrates with the popular swiftformat by Nick Lockwood and swift format provided with Swift 6 and later.

Native Formatter#

The formatting inside the editor is handled by Noctule’s native, built-in formatter.

Settings for the built-in formatter can be found at Preferences → Editor → Code Style → Swift (Noctule).

This formatter is needed to provide a good editor experience. It’s handling indentation, reformatting after refactorings, and more. But it’s not yet as powerful as the other formatters and does not.

If you rely on an external formatter, we recommend using the “Format on Save”.

If you would prefer to use an external formatter in the editor for Code → Reformat Code, please open a feature request on GitHub.

External Formatters#

Noctule supports running external formatters when you save a Swift file.

You can configure the settings at Preferences → Languages & Frameworks → Swift (Noctule). Two different formatter commands are supported: swiftformat and swift format of the Swift toolchain.

The “On Save” actions of your IDE are configured at Preferences → Tools → Actions on Save. But the settings provided by Noctule are exactly the same as on Noctule’s configuration page linked above.

Formatter of Swift 6 and later#

The swift format commands formats Swift files and is bundled with Swift 6 and later. The command is configured with .swift-format files in the project directories. The syntax of these files is documented on swift-format/Configuration.md.

swiftformat by Nick Lockwood#

swiftformat is a third-party formatter developed by Nick Lockwood at github.com/nicklockwood/SwiftFormat. This command is configured with .swiftformat files in the project directories. The syntax of these files is documented on SwiftFormat/README.md.