Skip to content

Commit

Permalink
Add cache path and directories only when commands accept them (#5851)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyDanny authored Nov 10, 2024
1 parent a731831 commit 3344fc6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
[SimplyDanny](https://github.com/SimplyDanny)
[#5167](https://github.com/realm/SwiftLint/issues/5167)

* Only pass cache path and directory paths to commands that accept these arguments
in the command plugin.
[SimplyDanny](https://github.com/SimplyDanny)
[#5848](https://github.com/realm/SwiftLint/issues/5848)

* Do not throw deprecation warning if deprecated property is not
presented in configuration.
[chipp](https://github.com/chipp)
Expand Down
22 changes: 18 additions & 4 deletions Plugins/SwiftLintCommandPlugin/SwiftLintCommandPlugin.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import Foundation
import PackagePlugin

private let commandsNotExpectingPaths: Set<String> = [
"docs",
"generate-docs",
"baseline",
"reporters",
"rules",
"version",
]

private let commandsWithoutCachPathOption: Set<String> = commandsNotExpectingPaths.union([
"analyze",
])

@main
struct SwiftLintCommandPlugin: CommandPlugin {
func performCommand(context: PluginContext, arguments: [String]) throws {
Expand All @@ -13,7 +26,7 @@ struct SwiftLintCommandPlugin: CommandPlugin {
let targets = targetNames.isEmpty
? context.package.targets
: try context.package.targets(named: targetNames)
guard !targets.isEmpty else {
if targets.isEmpty || !commandsNotExpectingPaths.isDisjoint(with: arguments) {
try run(with: context, arguments: arguments)
return
}
Expand All @@ -34,11 +47,12 @@ struct SwiftLintCommandPlugin: CommandPlugin {
process.currentDirectoryURL = URL(fileURLWithPath: context.package.directory.string)
process.executableURL = URL(fileURLWithPath: try context.tool(named: "swiftlint").path.string)
process.arguments = arguments
if !arguments.contains("analyze") {
// The analyze command does not support the `--cache-path` argument.
if commandsWithoutCachPathOption.isDisjoint(with: arguments) {
process.arguments! += ["--cache-path", "\(context.pluginWorkDirectory.string)"]
}
process.arguments! += [directory]
if commandsNotExpectingPaths.isDisjoint(with: arguments) {
process.arguments! += [directory]
}

try process.run()
process.waitUntilExit()
Expand Down

0 comments on commit 3344fc6

Please sign in to comment.