Skip to content

Instantly share code, notes, and snippets.

@watura
Last active October 7, 2022 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watura/79c26c2c443e3825e381df1278330ac5 to your computer and use it in GitHub Desktop.
Save watura/79c26c2c443e3825e381df1278330ac5 to your computer and use it in GitHub Desktop.
// swift-tools-version: 5.6
import PackageDescription
let package = Package(
name: "SwiftLintPlugin",
products: [
.plugin(name: "SwiftLintCLIPlugin", targets: ["SwiftLintCLIPlugin"])
],
targets: [
.binaryTarget(
name: "SwiftLintBinary",
url: "https://github.com/realm/SwiftLint/releases/download/<VERSION>/SwiftLintBinary-macos.artifactbundle.zip",
checksum: "<CHECKSUM>"
),
.plugin(
name: "SwiftLintCLIPlugin",
capability: .command(intent: .custom(verb: "lint", description: "Lint Swift Code")),
dependencies: ["SwiftLintBinary"]
)
]
)
//
// SwiftLintCLIPlugin.swift
import Foundation
import PackagePlugin
@main
struct SwiftLintCLIPlugin: CommandPlugin {
func performCommand(context: PluginContext, arguments: [String]) async throws {
let process = Process()
process.launchPath = try context.tool(named: "swiftlint").path.string
process.arguments = [
"lint",
"--no-cache",
"--config",
arguments.first! + "/.swiftlint.yml",
arguments.first!
]
try process.run()
process.waitUntilExit()
switch process.terminationStatus {
case EXIT_SUCCESS:
print("Lint the source code in \(arguments.first!).")
default:
let problem = "\(process.terminationReason):\(process.terminationStatus)"
Diagnostics.error("SwiftLint invocation failed: \(problem)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment