# Linting a Swift package with swift-format

DevFeed: [Linting a Swift package with swift-format](<https://devfeed.tech/articles/linting-a-swift-package-with-swift-format-24550.md>)

Original publisher: [Read original article](<https://medium.com/snapp-mobile/linting-a-swift-package-with-swift-format-a887b4e95a1e?source=rss----bcd96e620b02---4>)

Author: Oleksii Kolomiiets

Published: 2025-01-27T08:59:47Z

Content type: tutorial

Language: en

Sources: [Snapp Mobile](<https://devfeed.tech/sources/snapp-mobile-medium.md>)

Topics: [swift-package](<https://devfeed.tech/topics/swift-package.md>), [Swift](<https://devfeed.tech/topics/swift.md>), [Xcode](<https://devfeed.tech/topics/xcode.md>), [Developer Tools](<https://devfeed.tech/topics/developer-tools.md>), [software-development](<https://devfeed.tech/topics/software-development.md>), [Tool](<https://devfeed.tech/topics/tool.md>)

Tags: [built-in](<https://devfeed.tech/tags/built-in.md>), [formatting](<https://devfeed.tech/tags/formatting.md>), [ios](<https://devfeed.tech/tags/ios.md>), [linting](<https://devfeed.tech/tags/linting.md>), [package](<https://devfeed.tech/tags/package.md>), [plugin](<https://devfeed.tech/tags/plugin.md>), [plugins](<https://devfeed.tech/tags/plugins.md>), [swift](<https://devfeed.tech/tags/swift.md>), [swift-package](<https://devfeed.tech/tags/swift-package.md>), [swift-package-manager](<https://devfeed.tech/tags/swift-package-manager.md>)

## AI overview

The excerpt shows how to lint a Swift package during builds with Xcode 16's bundled `swift-format` and a Swift Package build tool plugin. The plugin runs a Bash script via `.buildCommand`; the script locates the formatter with `xcrun --find`, passes the package and `.swiftformat` configuration paths, and runs recursive linting. It filters Swift source files as build inputs and declares a stamp file as output so Xcode can track completion and refresh warnings on later builds. The script reformats formatter diagnostics into Xcode-readable file, line, column, and severity messages, then touches the stamp and exits successfully so lint warnings do not fail the build. The author reports `.prebuildCommand` produced path-related errors and uses `.buildCommand` instead. The example notes that its two-space indentation setting conflicts with four-space Xcode settings, initially producing many warnings; matching the setting and adjusting trailing commas removes them.

## Source excerpt

Linting your code is handy and effective way to keep your team's code style in shape. Nowadays it's hard to imagine a project without functionality that alerts developers with warnings or errors about issues in the code. It could be done with a simple script added to build phases. But what can you do when you don't have one? Packages are excluded from this option, but they still need to be maintained. Or at the very least, you'll feel much better knowing your package code is clean and consistent, and no one can make it messy without receiving a warning. This article explains how to enable linting for a package during its build process, using only the built-in swift-format tool -- no external libraries required. Preparation With Xcode 16, swift-format is included as part of the Xcode toolchain, eliminating the need for external libraries and making Swift file formatting more convenient. For more information, refer to the Getting swift-format section. 1. Create a package Launch Xcode and select File > New > Package from the menu. Chose Library and add the name to the package. 2. Add Plugin Package plugin is: Swift script that can be run as part of your buildA package could have plugins as extra, or be all about pluginsPackage plugins are available only within packageGeneral plugins can be made available to the outsideLets you access development tools on your machine More information about package plugins can be found in the Meet Swift Package plugins article. Start by creating a dedicated folder for all potential plugins, including the one you're currently working on. Ctrl + click on your package name in Xcode and select "New Folder" or use any other method to create a folder in the root of your project. Next, create a folder specifically for your plugin's logic. Since it will lint the package code using swift-format , the name SwiftFormatPlugin was chosen. By the end, the structure would look like this Now, let's add some content to plugin file import Foundation impor