Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>SwiftFormatNew to Visual Studio Code? Get it now.

SwiftFormat

vknabel

|
12,259 installs
| (2) | Free
Formatting Swift code with nicklockwood/SwiftFormat.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

SwiftFormat for VS Code

Prettify your Swift code automatically via SwiftFormat. You can use SwiftFormat installed globally or via the Swift Package Manager.

There are two formatters for Swift code. Use this extension if you wish to use nicklockwood/SwiftFormat. Use apple-swift-format if you want to use apple/swift-format.

Global Installation

You can install SwiftFormat globally using Homebrew or Mint

# Using Homebrew
$ brew update && brew install swiftformat
# Using Mint
$ mint install nicklockwood/SwiftFormat

Local Installation

Add the package to your dependencies in Package.swift:

// swift-tools-version:4.2

import PackageDescription

let package = Package(
    name: "Komondor",
    products: [ ... ],
    dependencies: [
        // My dependencies
        .package(url: "https://github.com/orta/PackageConfig.git", from: "0.0.1"),
        // Dev deps
        .package(url: "https://github.com/orta/Komondor.git", from: "0.0.1"),
+        .package(url: "https://github.com/nicklockwood/SwiftFormat.git", from: "0.35.8"),
    ],
    targets: [...]
)

Configuration

Config Type Default Description
swiftformat.enable Bool true Whether SwiftFormat should actually do something.
swiftformat.onlyEnableOnSwiftPMProjects Bool false Requires and uses a SwiftFormat as SwiftPM dependency.
swiftformat.onlyEnableWithConfig Bool false Only format if config present.
swiftformat.path [String] | String [/usr/bin/env, swiftformat] The location of the globally installed SwiftFormat.
swiftformat.options [String] [] Additional options for SwiftFormat.
swiftformat.configSearchPaths [String] [".swiftformat"] Possible paths for SwiftFormat config.

Contributors

  • Valentin Knabel, @vknabel, dev@vknabel.com, @vknabel on Twitter

License

vscode-swiftformat is available under the MIT license.

  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2023 Microsoft