-
-
Save watura/79c26c2c443e3825e381df1278330ac5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"] | |
) | |
] | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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