Skip to content

Commit d7d77d6

Browse files
authored
Clean up unused code and replace Path with URL to resolve warnings (#407)
* Remove unused code * Remove unused var binding and simplify case pattern * Replace Path with URL
1 parent b74ebfe commit d7d77d6

File tree

7 files changed

+25
-42
lines changed

7 files changed

+25
-42
lines changed

Plugins/GenerateCommandModels/plugin.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ struct GenerateCommandModelsPlugin: BuildToolPlugin {
55
func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] {
66
guard let target = target as? SourceModuleTarget else { return [] }
77

8-
let jsonSources = target.sourceFiles.map(\.path).filter { $0.extension == "json" }
8+
let jsonSources = target.sourceFiles.map(\.url).filter { $0.pathExtension == "json" }
99

10-
guard jsonSources.count > 0 else { return [] }
10+
guard !jsonSources.isEmpty else { return [] }
1111

12-
let outputPath = context.pluginWorkDirectory.appending("Commands.swift")
12+
let outputURL = context.pluginWorkDirectoryURL.appendingPathComponent("Commands.swift")
1313

1414
return [
1515
.buildCommand(
1616
displayName: "Generating Command Models from dumped JSON help",
17-
executable: try context.tool(named: "generate-command-models").path,
18-
arguments: ["--output-file", outputPath] + jsonSources,
17+
executable: try context.tool(named: "generate-command-models").url,
18+
arguments: [
19+
"--output-file", outputURL.path,
20+
] + jsonSources.map(\.path),
1921
inputFiles: jsonSources,
20-
outputFiles: [outputPath]
22+
outputFiles: [outputURL]
2123
),
2224
]
2325
}

Plugins/GenerateDocsReference/GenerateDocsReference.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ struct GenerateDocsReferencePlugin: CommandPlugin {
77
arguments: [String]
88
) async throws {
99
// Locate generation tool.
10-
let generationToolFile = try context.tool(named: "generate-docs-reference").path
11-
10+
let generationToolFile = try context.tool(named: "generate-docs-reference").url
1211
// Create an extractor to extract plugin-only arguments from the `arguments`
1312
// array.
1413
var extractor = ArgumentExtractor(arguments)
@@ -52,18 +51,20 @@ struct GenerateDocsReferencePlugin: CommandPlugin {
5251
guard builtArtifact.kind == .executable else { continue }
5352

5453
// Get the artifacts name.
55-
let executableName = builtArtifact.path.lastComponent
54+
let executableName = builtArtifact.url.lastPathComponent
5655

5756
print("Generating docs reference for \(executableName)...")
5857

59-
let outputFile = context.package.directory
60-
.appending("Documentation/SwiftlyDocs.docc/swiftly-cli-reference.md")
58+
let outputFile = context.package.directoryURL
59+
.appendingPathComponent("Documentation")
60+
.appendingPathComponent("SwiftlyDocs.docc")
61+
.appendingPathComponent("swiftly-cli-reference.md")
6162

6263
// Create generation tool arguments.
6364
var generationToolArguments = [
64-
builtArtifact.path.string,
65+
builtArtifact.url.path(percentEncoded: false),
6566
"--output-file",
66-
outputFile.string,
67+
outputFile.path(percentEncoded: false),
6768
]
6869
generationToolArguments.append(
6970
contentsOf: extractor.remainingArguments)

Plugins/GenerateDocsReference/GenerateDocsReferenceError.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ enum GenerateDocsReferencePluginError: Error {
66
case unknownBuildConfiguration(String)
77
case buildFailed(String)
88
case createOutputDirectoryFailed(Error)
9-
case subprocessFailedNonZeroExit(Path, Int32)
10-
case subprocessFailedError(Path, Error)
9+
case subprocessFailedNonZeroExit(URL, Int32)
10+
case subprocessFailedError(URL, Error)
1111
}
1212

1313
extension GenerateDocsReferencePluginError: CustomStringConvertible {
@@ -23,12 +23,12 @@ extension GenerateDocsReferencePluginError: CustomStringConvertible {
2323
"""
2424
case let .subprocessFailedNonZeroExit(tool, exitCode):
2525
return """
26-
'\(tool.lastComponent)' invocation failed with a nonzero exit code: \
26+
'\(tool.lastPathComponent)' invocation failed with a nonzero exit code: \
2727
'\(exitCode)'.
2828
"""
2929
case let .subprocessFailedError(tool, error):
3030
return """
31-
'\(tool.lastComponent)' invocation failed: \
31+
'\(tool.lastPathComponent)' invocation failed: \
3232
'\(error.localizedDescription)'
3333
"""
3434
}

Plugins/GenerateDocsReference/PackagePlugin+Helpers.swift

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,11 @@ extension ArgumentExtractor {
2525
}
2626
}
2727

28-
extension Path {
29-
func createOutputDirectory() throws {
30-
do {
31-
try FileManager.default.createDirectory(
32-
atPath: self.string,
33-
withIntermediateDirectories: true
34-
)
35-
} catch {
36-
throw GenerateDocsReferencePluginError.createOutputDirectoryFailed(error)
37-
}
38-
}
39-
28+
extension URL {
4029
func exec(arguments: [String]) throws {
4130
do {
4231
let process = Process()
43-
process.executableURL = URL(fileURLWithPath: self.string)
32+
process.executableURL = self
4433
process.arguments = arguments
4534
try process.run()
4635
process.waitUntilExit()
@@ -58,15 +47,6 @@ extension Path {
5847
}
5948
}
6049

61-
extension PackageManager.BuildResult.BuiltArtifact {
62-
func matchingProduct(context: PluginContext) -> Product? {
63-
context
64-
.package
65-
.products
66-
.first { $0.name == self.path.lastComponent }
67-
}
68-
}
69-
7050
extension Product {
7151
func hasDependency(named name: String) -> Bool {
7252
self.recursiveTargetDependencies

Sources/Swiftly/List.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct List: SwiftlyCommand {
5555
let toolchains = config.listInstalledToolchains(selector: selector).sorted { $0 > $1 }
5656
let (inUse, _) = try await selectToolchain(ctx, config: &config)
5757

58-
var installedToolchainInfos = toolchains.compactMap { toolchain -> InstallToolchainInfo? in
58+
let installedToolchainInfos = toolchains.compactMap { toolchain -> InstallToolchainInfo? in
5959
InstallToolchainInfo(
6060
version: toolchain,
6161
inUse: inUse == toolchain,

Sources/Swiftly/OutputSchema.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ struct InstallToolchainInfo: OutputData {
249249
let versionContainer = try container.nestedContainer(
250250
keyedBy: ToolchainVersionCodingKeys.self, forKey: .version
251251
)
252-
let name = try versionContainer.decode(String.self, forKey: .name)
252+
_ = try versionContainer.decode(String.self, forKey: .name)
253253

254254
switch try versionContainer.decode(String.self, forKey: .type) {
255255
case "stable":

Sources/Swiftly/Update.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ struct Update: SwiftlyCommand {
192192
default:
193193
fatalError("unreachable")
194194
}
195-
case let .xcode:
195+
case .xcode:
196196
throw SwiftlyError(message: "xcode cannot be updated from swiftly")
197197
}
198198
}

0 commit comments

Comments
 (0)