79475500

Date: 2025-02-28 12:27:11
Score: 1
Natty:
Report link

I found a solution to this issue and am sharing my findings:

Linting Swift Packages in Xcode 16 Without External Dependencies

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.

Solution Summary

You can lint your Swift package without third-party dependencies by:

  1. Creating a build tool plugin in your Package.swift file
  2. Implementing the plugin to use the built-in swift-format from Xcode 16
  3. Adding the plugin to your target

When your package builds, Xcode will show warnings for formatting issues like the inconsistent indentation in my example:

struct MyPackage {
    var a: Int
       var b: Int  // This will show a warning in Xcode
    var c: Int
}

The warnings are displayed directly in Xcode’s issue navigator during the build process.

screenshots that shows warning Indentation unindent by 3 spaces

For a comprehensive guide with step-by-step instructions and sample code, refer to this article: Linting a Swift Package with swift-format

Note that while the article references adding swift-format as a dependency, with Xcode 16 you can simplify this approach by using the built-in toolchain version instead.

Reasons:
  • Blacklisted phrase (1): this article
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Oleksii Kolomiiets