Skip to content

Improve _format command #3684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions Sources/Commands/SwiftPackageTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,26 +265,23 @@ extension SwiftPackageTool {
: swiftFormatFlags

// Process each target in the root package.
for target in package.targets {
for file in target.sources.paths {
// Only process Swift sources.
guard let ext = file.extension, ext == SupportedLanguageExtension.swift.rawValue else {
continue
}
let paths = package.targets.flatMap { target in
target.sources.paths.filter { file in
file.extension == SupportedLanguageExtension.swift.rawValue
}
}.map { $0.pathString }

let args = [swiftFormat.pathString] + formatOptions + [file.pathString]
print("Running:", args.map{ $0.spm_shellEscaped() }.joined(separator: " "))
let args = [swiftFormat.pathString] + formatOptions + [rootManifest.path.pathString] + paths
print("Running:", args.map{ $0.spm_shellEscaped() }.joined(separator: " "))

let result = try Process.popen(arguments: args)
let output = try (result.utf8Output() + result.utf8stderrOutput())
let result = try Process.popen(arguments: args)
let output = try (result.utf8Output() + result.utf8stderrOutput())

if result.exitStatus != .terminated(code: 0) {
print("Non-zero exit", result.exitStatus)
}
if !output.isEmpty {
print(output)
}
}
if result.exitStatus != .terminated(code: 0) {
print("Non-zero exit", result.exitStatus)
}
if !output.isEmpty {
print(output)
}
}
}
Expand Down