Skip to content

Commit 4be001c

Browse files
timthehelipilotmpospese
authored andcommitted
[CM-757] Create a SwiftLint Plugin for a Swift Package
1 parent cfab76b commit 4be001c

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

Package.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@ let package = Package(
1616
targets: ["YCatalogViewer"]
1717
)
1818
],
19-
dependencies: [
20-
// Dependencies declare other packages that this package depends on.
21-
// .package(url: /* package url */, from: "1.0.0"),
22-
],
2319
targets: [
2420
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2521
// Targets can depend on other targets in this package, and on products in packages this package depends on.
22+
.binaryTarget(
23+
name: "SwiftLintBinary",
24+
url: "https://github.com/realm/SwiftLint/releases/download/0.47.1/SwiftLintBinary-macos.artifactbundle.zip",
25+
checksum: "82ef90b7d76b02e41edd73423687d9cedf0bb9849dcbedad8df3a461e5a7b555"
26+
),
27+
.plugin(
28+
name: "SwiftLint",
29+
capability: .buildTool(),
30+
dependencies: ["SwiftLintBinary"]
31+
),
2632
.target(
2733
name: "YCatalogViewer",
28-
dependencies: []
34+
dependencies: [],
35+
plugins: ["SwiftLint"]
2936
),
3037
.testTarget(
3138
name: "YCatalogViewerTests",
32-
dependencies: ["YCatalogViewer"]
39+
dependencies: ["YCatalogViewer"],
40+
plugins: ["SwiftLint"]
3341
)
3442
]
3543
)

Plugins/SwiftLint/main.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// main.swift
3+
// YCatalogViewer
4+
//
5+
// Created by Tim Barett on 7/20/22.
6+
// Copyright © 2021 Y Media Labs. All rights reserved.
7+
//
8+
9+
import PackagePlugin
10+
11+
@main
12+
struct SwiftLint: BuildToolPlugin {
13+
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
14+
[
15+
.buildCommand(
16+
displayName: "Linting \(target.name)...",
17+
executable: try context.tool(named: "swiftlint").path,
18+
arguments: [
19+
"lint",
20+
"--in-process-sourcekit",
21+
"--config",
22+
"\(context.package.directory.string)/.swiftlint.yml",
23+
"--path",
24+
target.directory.string
25+
],
26+
environment: [:]
27+
)
28+
]
29+
}
30+
}

0 commit comments

Comments
 (0)