diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e5f629d1..10011011 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,14 +1,9 @@ # Contributing to Layout -- [Dependencies](#dependencies) - [Open Package in Xcode](#open-package-in-xcode) - [Static Analysis](#static-analysis) - [Testing](#testing) -## Dependencies - -Follow the [Swift Package Resources installation instructions](https://github.com/TinderApp/Swift-Package-Resources) to install tooling dependencies. - ## Open Package in Xcode > The file header comment template will also be installed. @@ -21,12 +16,6 @@ make open > SwiftLint violations are visible in Xcode as well. -Package dependencies must be resolved to download the SwiftLint binary. - -``` -swift package resolve -``` - To run SwiftLint from the command line: ``` @@ -39,12 +28,6 @@ To run analysis rules: make analyze ``` -To enable new rules whenever SwiftLint is upgraded to a new version: - -``` -make rules -``` - ## Testing To re-record all existing snapshot references, delete all using the following command and then run the tests. diff --git a/Makefile b/Makefile index fc49946f..a4e0e42c 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,3 @@ -# -# The SwiftLint recipes require the Swift Package Resources scripts to be installed. -# -# https://github.com/TinderApp/Swift-Package-Resources#installation -# - .PHONY: open open: fix open: @@ -24,7 +18,8 @@ fix: .PHONY: lint lint: format ?= emoji lint: - @swiftlint lint --strict --progress --reporter "$(format)" + @swift package plugin \ + swiftlint lint --strict --progress --reporter "$(format)" .PHONY: analyze analyze: target ?= Layout @@ -40,11 +35,8 @@ analyze: -configuration "Debug" \ CODE_SIGNING_ALLOWED="NO" \ > "$$XCODEBUILD_LOG"; \ - swiftlint analyze --strict --progress --reporter "$(format)" --compiler-log-path "$$XCODEBUILD_LOG" - -.PHONY: rules -rules: - @swiftlint rules | lint-rules + swift package plugin \ + swiftlint analyze --strict --progress --reporter "$(format)" --compiler-log-path "$$XCODEBUILD_LOG" .PHONY: delete-snapshots delete-snapshots: diff --git a/Package.swift b/Package.swift index ec820ff0..81bccc38 100644 --- a/Package.swift +++ b/Package.swift @@ -49,6 +49,12 @@ let package = Package( plugins: [ .plugin(name: SwiftLint.plugin), ]), + .plugin( + name: "SwiftLintCommand", + capability: .command(intent: .custom(verb: "swiftlint", description: "SwiftLint Command Plugin")), + dependencies: [ + .target(name: SwiftLint.binary) + ]), .plugin( name: SwiftLint.plugin, capability: .buildTool(), diff --git a/Plugins/SwiftLintCommand/SwiftLintCommand.swift b/Plugins/SwiftLintCommand/SwiftLintCommand.swift new file mode 100644 index 00000000..b60a6f4b --- /dev/null +++ b/Plugins/SwiftLintCommand/SwiftLintCommand.swift @@ -0,0 +1,35 @@ +// +// Copyright © 2024 Tinder (Match Group, LLC) +// + +import Foundation +import PackagePlugin + +@main +internal struct SwiftLintCommand: CommandPlugin { + + private let toolName: String = "swiftlint" + + internal func performCommand( + context: PluginContext, + arguments: [String] + ) throws { + let tool: PluginContext.Tool = try context.tool(named: toolName) + guard !arguments.contains("--cache-path") + else { return Diagnostics.error("Setting Cache Path Not Allowed") } + let process: Process = .init() + process.currentDirectoryURL = URL(fileURLWithPath: context.package.directory.string) + process.executableURL = URL(fileURLWithPath: tool.path.string) + process.arguments = arguments + ["--cache-path", "\(context.pluginWorkDirectory.string)"] + try process.run() + process.waitUntilExit() + switch process.terminationReason { + case .exit: + break + case .uncaughtSignal: + return Diagnostics.error("Uncaught Signal") + } + guard process.terminationStatus == EXIT_SUCCESS + else { return Diagnostics.error("Command Failed") } + } +}