Skip to content

Commit 6a98663

Browse files
committed
[SwiftRefactor] PackageManifest: Inline Configuration into AddPackageTarget.Context
1 parent db2b78f commit 6a98663

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

Sources/SwiftRefactor/PackageManifest/AddPackageTarget.swift

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ import SwiftSyntaxBuilder
1818
public struct AddPackageTarget: ManifestEditRefactoringProvider {
1919
public struct Context {
2020
public let target: PackageTarget
21-
public let configuration: Configuration
21+
public var testHarness: TestHarness
2222

23-
public init(target: PackageTarget, configuration: Configuration = .init()) {
23+
public init(
24+
target: PackageTarget,
25+
testHarness: TestHarness = .default
26+
) {
2427
self.target = target
25-
self.configuration = configuration
28+
self.testHarness = testHarness
2629
}
2730
}
2831

@@ -50,27 +53,13 @@ public struct AddPackageTarget: ManifestEditRefactoringProvider {
5053
public static let `default`: TestHarness = .swiftTesting
5154
}
5255

53-
/// Additional configuration information to guide the package editing
54-
/// process.
55-
public struct Configuration {
56-
/// The test harness to use.
57-
public var testHarness: TestHarness
58-
59-
public init(
60-
testHarness: TestHarness = .default
61-
) {
62-
self.testHarness = testHarness
63-
}
64-
}
65-
6656
/// Add the given target to the manifest, producing a set of edit results
6757
/// that updates the manifest and adds some source files to stub out the
6858
/// new target.
6959
public static func manifestRefactor(
7060
syntax manifest: SourceFileSyntax,
7161
in context: Context
7262
) throws -> PackageEdit {
73-
let configuration = context.configuration
7463
guard let packageCall = manifest.findCall(calleeName: "Package") else {
7564
throw ManifestEditError.cannotFindPackage
7665
}
@@ -120,7 +109,7 @@ public struct AddPackageTarget: ManifestEditRefactoringProvider {
120109
addPrimarySourceFile(
121110
outerPath: outerPath,
122111
target: target,
123-
configuration: configuration,
112+
in: context,
124113
to: &auxiliaryFiles
125114
)
126115

@@ -176,7 +165,7 @@ public struct AddPackageTarget: ManifestEditRefactoringProvider {
176165
fileprivate static func addPrimarySourceFile(
177166
outerPath: String,
178167
target: PackageTarget,
179-
configuration: Configuration,
168+
in context: Context,
180169
to auxiliaryFiles: inout AuxiliaryFiles
181170
) {
182171
let sourceFilePath = "\(outerPath)/\(target.name)/\(target.name).swift"
@@ -188,7 +177,7 @@ public struct AddPackageTarget: ManifestEditRefactoringProvider {
188177

189178
// Add appropriate test module dependencies.
190179
if target.type == .test {
191-
switch configuration.testHarness {
180+
switch context.testHarness {
192181
case .none:
193182
break
194183

@@ -229,7 +218,7 @@ public struct AddPackageTarget: ManifestEditRefactoringProvider {
229218
"""
230219

231220
case .test:
232-
switch configuration.testHarness {
221+
switch context.testHarness {
233222
case .none:
234223
sourceFileText = """
235224
\(imports)

Tests/SwiftRefactorTest/ManifestEditTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,7 @@ final class ManifestEditTests: XCTestCase {
661661
name: "MyTest target-name",
662662
type: .test
663663
),
664-
configuration: .init(
665-
testHarness: .swiftTesting
666-
)
664+
testHarness: .swiftTesting
667665
)
668666
)
669667
}

0 commit comments

Comments
 (0)