I'm using this plugin to lint my package with swift-format:
// SwiftFormatPlugin.swift
import Foundation
import PackagePlugin
@main struct SwiftFormatPlugin: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] {
let directory = context.package.directoryURL
let plugin = directory.appending(path: "Plugins/SwiftFormatPlugin")
return [
.buildCommand(
displayName: "SwiftFormatPlugin",
executable: URL(filePath: "/bin/bash"),
arguments: [
plugin.appending(component: "script.sh").path,
directory.path,
directory.appending(path: ".swift-format").path
],
environment: [:],
inputFiles: [],
outputFiles: []
)
]
}
}
This is the contents of my Package.swift
file:
// Package.swift
import PackageDescription
let package = Package(
name: "MyLibrary",
products: [
.library(
name: "MyLibrary",
targets: ["MyLibrary"]
)
],
targets: [
.target(
name: "MyLibrary",
plugins: [
.plugin(name: "SwiftFormatPlugin")
]
),
.plugin(
name: "SwiftFormatPlugin",
capability: .buildTool(),
path: "Plugins/SwiftFormatPlugin"
)
]
)
And finally the script my plugin is executing:
#!/bin/bash
# script.sh
echo "SwiftFormatPlugin test .................."
It works alright as I am getting desired output when building:
SwiftFormatPlugin test ..................
But I'm also getting this:
I want to fix that, but how do I "check" that option? The script phase or the mentioned checkbox is nowhere in the UI for package targets.