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()