From 3344fc6d31b921b333f601b185f2da75e342a567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sun, 10 Nov 2024 15:32:16 +0100 Subject: [PATCH] Add cache path and directories only when commands accept them (#5851) --- CHANGELOG.md | 5 +++++ .../SwiftLintCommandPlugin.swift | 22 +++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffb00ebc19..cfdf749b3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Plugins/SwiftLintCommandPlugin/SwiftLintCommandPlugin.swift b/Plugins/SwiftLintCommandPlugin/SwiftLintCommandPlugin.swift index d254ff8fdd..e1f562fd18 100644 --- a/Plugins/SwiftLintCommandPlugin/SwiftLintCommandPlugin.swift +++ b/Plugins/SwiftLintCommandPlugin/SwiftLintCommandPlugin.swift @@ -1,6 +1,19 @@ import Foundation import PackagePlugin +private let commandsNotExpectingPaths: Set = [ + "docs", + "generate-docs", + "baseline", + "reporters", + "rules", + "version", +] + +private let commandsWithoutCachPathOption: Set = commandsNotExpectingPaths.union([ + "analyze", +]) + @main struct SwiftLintCommandPlugin: CommandPlugin { func performCommand(context: PluginContext, arguments: [String]) throws { @@ -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 } @@ -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()