nicklockwood/SwiftFormat

Trigger swift package plugin as dependency of target

Open

#1,813 opened on Aug 7, 2024

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Swift (686 forks)batch import
help wantedquestion

Repository metrics

Stars
 (8,801 stars)
PR merge metrics
 (Avg merge 13h 11m) (25 merged PRs in 30d)

Description

I want to include swift format into a custom swift package that runs every time the package is being build.

Here is the Package.swift file:

// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "test-format",
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "test-format",
            targets: ["test-format"]),
    ],
    dependencies: [
//        .package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", from: "0.55.1"), // this works
        .package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.54.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: "test-format",
            plugins: [
//                .plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins"), // this works
                .plugin(name: "SwiftFormatPlugin", package: "SwiftFormat"),
            ]),
        .testTarget(
            name: "test-formatTests",
            dependencies: ["test-format"]),
    ]
)

When I try and build the package from within Xcode (cmd + B), I get the following error (same for running tests):

When attempting to build from command line I get a different error:

Environment:

  • clean swift package created using Xcode 14.2

Goal:

Contributor guide