SwiftLint for VS Code

April 11, 2025 ยท View on GitHub

VS Code extension to enforce Swift style and conventions via SwiftLint. You can use SwiftLint installed globally or via the Swift Package Manager.

Global Installation

You can install SwiftLint globally using Homebrew or Mint. For a local setup you can use the Swift Package Manager.

# Using Homebrew
$ brew install swiftlint
# Using Mint
$ mint install realm/SwiftLint
# Manually
$ git clone https://github.com/realm/SwiftLint.git
$ swift build -c release

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/realm/SwiftLint.git", from: "0.58.2"),
    ],
    targets: [...]
)

Configuration

ConfigTypeDefaultDescription
swiftlint.enableBooltrueWhether SwiftLint should actually do something.
swiftlint.onlyEnableOnSwiftPMProjectsBoolfalseRequires and uses a SwiftLint as SwiftPM dependency. This will cause the extension to build the Swift package upon first launch.
swiftlint.onlyEnableWithConfigBoolfalseOnly lint if config present. Requires swiftlint.configSearchPaths.
swiftlint.pathStringswiftlintThe location of the globally installed SwiftLint (resolved with the current path if only a filename).
swiftlint.additionalParameters[String][]Additional parameters to pass to SwiftLint.
swiftlint.configSearchPaths[String][]Possible paths for SwiftLint config. This disables nested configurations!
swiftlint.autoLintWorkspaceBooltrueAutomatically lint the whole project right after start.

Note that when swiftlint.onlyEnableOnSwiftPMProjects is enabled, the extension will only run swiftlint executables built as part of the Swift package open in the workspace. It will try to build the binary once on first launch. If the build fails, the extension will not fall back to a globally installed swiftlint. If you prefer a locally built swiftlint, but want to skip the automatic initial build, let swiftlint.path point to the local executable you have built manually or by other means independent of the extension.

Commands

Short TitleCommand
SwiftLint: Lint workspaceswiftlint.lintWorkspace
SwiftLint: Fix workspaceswiftlint.fixWorkspace
SwiftLint: Fix documentswiftlint.fixDocument
SwiftLint: Fix all known issuessource.fixAll.swiftlint

To automatically fix all issues within a document on save, add the following to your .vscode/settings.json:

{
  "editor.codeActionsOnSave": {
    "source.fixAll": true
  }
}

License

vscode-swiftlint is available under the MIT license.