Run SwiftLint as a SPM plugin.

This commit is contained in:
Doug 2023-01-09 14:20:25 +00:00
parent 6134ad3866
commit fb9da2d7dc
6 changed files with 130 additions and 8 deletions

View File

@ -2795,7 +2795,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export PATH=\"$PATH:/opt/homebrew/bin\"\nif which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
shellScript = "xcrun --sdk macosx swift package -c release plugin swiftlint\n";
};
A7130911BCB2DF3D249A1836 /* 🛠 SwiftGen */ = {
isa = PBXShellScriptBuildPhase;

View File

@ -9,6 +9,15 @@
"version" : "1.6.0"
}
},
{
"identity" : "collectionconcurrencykit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/JohnSundell/CollectionConcurrencyKit.git",
"state" : {
"revision" : "b4f23e24b5a1bff301efc5e70871083ca029ff95",
"version" : "0.2.0"
}
},
{
"identity" : "devicekit",
"kind" : "remoteSourceControl",
@ -108,6 +117,15 @@
"version" : "7.30.2"
}
},
{
"identity" : "sourcekitten",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/SourceKitten.git",
"state" : {
"revision" : "fc12c0f182c5cf80781dd933b17a82eb98bd7c61",
"version" : "0.33.1"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
@ -126,6 +144,14 @@
"version" : "1.10.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "a2d31e8880224f5a619f24bf58c122836faf99ff"
}
},
{
"identity" : "swiftformat",
"kind" : "remoteSourceControl",
@ -135,6 +161,15 @@
"version" : "0.50.7"
}
},
{
"identity" : "swiftlint",
"kind" : "remoteSourceControl",
"location" : "https://github.com/realm/SwiftLint",
"state" : {
"branch" : "main",
"revision" : "68dc0f58d2e3a2e2b44457ffa0753056f38736f6"
}
},
{
"identity" : "swiftstate",
"kind" : "remoteSourceControl",
@ -162,6 +197,24 @@
"version" : "1.9.6"
}
},
{
"identity" : "swiftytexttable",
"kind" : "remoteSourceControl",
"location" : "https://github.com/scottrhoyt/SwiftyTextTable.git",
"state" : {
"revision" : "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3",
"version" : "0.9.0"
}
},
{
"identity" : "swxmlhash",
"kind" : "remoteSourceControl",
"location" : "https://github.com/drmohundro/SWXMLHash.git",
"state" : {
"revision" : "4d0f62f561458cbe1f732171e625f03195151b60",
"version" : "7.0.1"
}
},
{
"identity" : "yams",
"kind" : "remoteSourceControl",

View File

@ -91,12 +91,7 @@ targets:
basedOnDependencyAnalysis: false
shell: /bin/sh
script: |
export PATH="$PATH:/opt/homebrew/bin"
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
xcrun --sdk macosx swift package -c release plugin swiftlint
- name: 🧹 SwiftFormat
runOnlyWhenInstalling: false
basedOnDependencyAnalysis: false

View File

@ -1,5 +1,14 @@
{
"pins" : [
{
"identity" : "collectionconcurrencykit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/JohnSundell/CollectionConcurrencyKit.git",
"state" : {
"revision" : "b4f23e24b5a1bff301efc5e70871083ca029ff95",
"version" : "0.2.0"
}
},
{
"identity" : "element-design-tokens",
"kind" : "remoteSourceControl",
@ -9,6 +18,15 @@
"version" : "0.0.3"
}
},
{
"identity" : "sourcekitten",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/SourceKitten.git",
"state" : {
"revision" : "fc12c0f182c5cf80781dd933b17a82eb98bd7c61",
"version" : "0.33.1"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
@ -18,6 +36,14 @@
"version" : "1.2.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "a2d31e8880224f5a619f24bf58c122836faf99ff"
}
},
{
"identity" : "swiftformat",
"kind" : "remoteSourceControl",
@ -27,6 +53,15 @@
"version" : "0.50.7"
}
},
{
"identity" : "swiftlint",
"kind" : "remoteSourceControl",
"location" : "https://github.com/realm/SwiftLint",
"state" : {
"branch" : "main",
"revision" : "68dc0f58d2e3a2e2b44457ffa0753056f38736f6"
}
},
{
"identity" : "swiftui-introspect",
"kind" : "remoteSourceControl",
@ -36,6 +71,24 @@
"version" : "0.1.4"
}
},
{
"identity" : "swiftytexttable",
"kind" : "remoteSourceControl",
"location" : "https://github.com/scottrhoyt/SwiftyTextTable.git",
"state" : {
"revision" : "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3",
"version" : "0.9.0"
}
},
{
"identity" : "swxmlhash",
"kind" : "remoteSourceControl",
"location" : "https://github.com/drmohundro/SWXMLHash.git",
"state" : {
"revision" : "4d0f62f561458cbe1f732171e625f03195151b60",
"version" : "7.0.1"
}
},
{
"identity" : "yams",
"kind" : "remoteSourceControl",

View File

@ -20,6 +20,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.0"),
.package(url: "https://github.com/jpsim/Yams", from: "5.0.1"),
/* Package plug-ins */
.package(url: "https://github.com/realm/SwiftLint", branch: "main"),
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.50.4")
],
targets: [
@ -37,6 +38,12 @@ let package = Package(
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "Yams", package: "Yams")
],
path: "Tools/Sources")
path: "Tools/Sources"),
.plugin(name: "SwiftLint",
capability: .command(intent: .custom(verb: "swiftlint", description: "Run swiftlint on the project directory")),
dependencies: [
.product(name: "swiftlint", package: "SwiftLint")
],
path: "Tools/Plugins/SwiftLint")
]
)

View File

@ -0,0 +1,14 @@
import Foundation
import PackagePlugin
@main
struct SwiftLint: CommandPlugin {
func performCommand(context: PackagePlugin.PluginContext, arguments: [String]) async throws {
let swiftlint = try context.tool(named: "swiftlint")
let process = Process()
process.executableURL = URL(fileURLWithPath: swiftlint.path.string)
process.currentDirectoryURL = URL(fileURLWithPath: context.package.directory.string)
try process.run()
}
}