Skip to content

Commit 000acac

Browse files
authored
Remove mutation requirement for command line actions (#1076)
rdar://139495161
1 parent 3b39d07 commit 000acac

16 files changed

+77
-79
lines changed

Sources/SwiftDocCUtilities/Action/Action.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import SwiftDocC
1616
/// An action represents a discrete documentation task; it takes options and inputs, performs its work, reports any problems it encounters, and outputs it generates.
1717
package protocol AsyncAction {
1818
/// Performs the action and returns an ``ActionResult``.
19-
mutating func perform(logHandle: inout LogHandle) async throws -> ActionResult
19+
func perform(logHandle: inout LogHandle) async throws -> ActionResult
2020
}
2121

2222
package extension AsyncAction {
23-
mutating func perform(logHandle: LogHandle) async throws -> ActionResult {
23+
func perform(logHandle: LogHandle) async throws -> ActionResult {
2424
var logHandle = logHandle
2525
return try await perform(logHandle: &logHandle)
2626
}

Sources/SwiftDocCUtilities/Action/Actions/Convert/ConvertAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public struct ConvertAction: AsyncAction {
271271
indexHTML = nil
272272
}
273273

274-
var coverageAction = CoverageAction(
274+
let coverageAction = CoverageAction(
275275
documentationCoverageOptions: documentationCoverageOptions,
276276
workingDirectory: temporaryFolder,
277277
fileManager: fileManager)

Sources/SwiftDocCUtilities/Action/Actions/CoverageAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public struct CoverageAction: AsyncAction {
2727
let workingDirectory: URL
2828
private let fileManager: FileManagerProtocol
2929

30-
public mutating func perform(logHandle: inout LogHandle) async throws -> ActionResult {
30+
public func perform(logHandle: inout LogHandle) async throws -> ActionResult {
3131
switch documentationCoverageOptions.level {
3232
case .brief, .detailed:
3333
print(" --- Experimental coverage output enabled. ---", to: &logHandle)

Sources/SwiftDocCUtilities/Action/Actions/EmitGeneratedCurationAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct EmitGeneratedCurationAction: AsyncAction {
4141
self.fileManager = fileManager
4242
}
4343

44-
mutating func perform(logHandle: inout LogHandle) async throws -> ActionResult {
44+
func perform(logHandle: inout LogHandle) async throws -> ActionResult {
4545
let inputProvider = DocumentationContext.InputsProvider(fileManager: fileManager)
4646
let (bundle, dataProvider) = try inputProvider.inputsAndDataProvider(
4747
startingPoint: catalogURL,

Sources/SwiftDocCUtilities/Action/Actions/IndexAction.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public struct IndexAction: AsyncAction {
1818
let bundleIdentifier: String
1919

2020
var diagnosticEngine: DiagnosticEngine
21-
22-
private var dataProvider: LocalFileSystemDataProvider!
2321

2422
/// Initializes the action with the given validated options, creates or uses the given action workspace & context.
2523
public init(documentationBundleURL: URL, outputURL: URL, bundleIdentifier: String, diagnosticEngine: DiagnosticEngine = .init()) throws {
@@ -34,15 +32,15 @@ public struct IndexAction: AsyncAction {
3432

3533
/// Converts each eligible file from the source documentation bundle,
3634
/// saves the results in the given output alongside the template files.
37-
mutating public func perform(logHandle: inout LogHandle) async throws -> ActionResult {
35+
public func perform(logHandle: inout LogHandle) async throws -> ActionResult {
3836
let problems = try buildIndex()
3937
diagnosticEngine.emit(problems)
4038

4139
return ActionResult(didEncounterError: !diagnosticEngine.problems.isEmpty, outputs: [outputURL])
4240
}
4341

44-
mutating private func buildIndex() throws -> [Problem] {
45-
dataProvider = try LocalFileSystemDataProvider(rootURL: rootURL)
42+
private func buildIndex() throws -> [Problem] {
43+
let dataProvider = try LocalFileSystemDataProvider(rootURL: rootURL)
4644
let indexBuilder = NavigatorIndex.Builder(renderNodeProvider: FileSystemRenderNodeProvider(fileSystemProvider: dataProvider),
4745
outputURL: outputURL,
4846
bundleIdentifier: bundleIdentifier,

Sources/SwiftDocCUtilities/Action/Actions/Init/InitAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public struct InitAction: AsyncAction {
7272
/// Generates a documentation catalog from a catalog template.
7373
///
7474
/// - Parameter logHandle: The file handle that the convert and preview actions will print debug messages to.
75-
public mutating func perform(logHandle: inout LogHandle) async throws -> ActionResult {
75+
public func perform(logHandle: inout LogHandle) async throws -> ActionResult {
7676
let diagnosticEngine: DiagnosticEngine = DiagnosticEngine(treatWarningsAsErrors: false)
7777
diagnosticEngine.filterLevel = .warning
7878
diagnosticEngine.add(DiagnosticConsoleWriter(formattingOptions: []))

Sources/SwiftDocCUtilities/Action/Actions/Merge/MergeAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct MergeAction: AsyncAction {
3333
}
3434
}
3535

36-
mutating func perform(logHandle: inout LogHandle) async throws -> ActionResult {
36+
func perform(logHandle: inout LogHandle) async throws -> ActionResult {
3737
guard let firstArchive = archives.first else {
3838
// A validation warning should have already been raised in `Docc/Merge/InputAndOutputOptions/validate()`.
3939
return ActionResult(didEncounterError: true, outputs: [])

Sources/SwiftDocCUtilities/Action/Actions/TransformForStaticHostingAction.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ struct TransformForStaticHostingAction: AsyncAction {
4444

4545
/// Converts each eligible file from the source archive and
4646
/// saves the results in the given output folder.
47-
mutating func perform(logHandle: inout LogHandle) async throws -> ActionResult {
47+
func perform(logHandle: inout LogHandle) async throws -> ActionResult {
4848
try emit()
4949
return ActionResult(didEncounterError: false, outputs: [outputURL])
5050
}
5151

52-
mutating private func emit() throws {
52+
private func emit() throws {
5353
// If the emit is to create the static hostable content outside of the source archive
5454
// then the output folder needs to be set up and the archive data copied
5555
// to the new folder.

Tests/SwiftDocCUtilitiesTests/ConvertActionStaticHostableTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ConvertActionStaticHostableTests: StaticHostingBaseTests {
3232
let basePath = "test/folder"
3333
let indexHTML = Folder.testHTMLTemplate(basePath: "test/folder")
3434

35-
var action = try ConvertAction(
35+
let action = try ConvertAction(
3636
documentationBundleURL: bundleURL,
3737
outOfProcessResolver: nil,
3838
analyze: false,

0 commit comments

Comments
 (0)