Skip to content

Commit 6eb3e61

Browse files
leogdionclaude
andcommitted
Add comprehensive documentation comments to DocumentationHarness public API
Added DocC-style documentation comments to all public and package access level items in the DocumentationHarness module, including: - Package structs: CodeBlock, ValidationResult, DocumentationTestHarness - Package enums: TestType, ValidationError, ProcessError, FileSearchError, CodeBlockExtractorError - Package protocols: SyntaxValidator, FileSearcher - Package typealiases: CodeBlockExtractor - All public properties and methods with parameter documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 45dca6a commit 6eb3e61

10 files changed

Lines changed: 58 additions & 9 deletions

Sources/DocumentationHarness/CodeBlock.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929

3030
import Foundation
3131

32+
/// Represents a code block extracted from documentation
3233
package struct CodeBlock {
34+
/// The raw Swift code content
3335
internal let code: String
36+
/// Line number where this code block starts in the source file
3437
internal let lineNumber: Int
38+
/// The type of code block (example, shell command, etc.)
3539
internal let blockType: CodeBlockType
3640
}

Sources/DocumentationHarness/CodeBlockExtractor.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,9 @@
2727
// OTHER DEALINGS IN THE SOFTWARE.
2828
//
2929

30+
/// Function type for extracting code blocks from markdown content
31+
/// - Parameter content: The markdown content to parse
32+
/// - Returns: Array of extracted code blocks
33+
/// - Throws: CodeBlockExtractorError if extraction fails
3034
package typealias CodeBlockExtractor = @Sendable (String) throws(CodeBlockExtractorError) ->
3135
[CodeBlock]

Sources/DocumentationHarness/CodeBlockExtractorError.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
// OTHER DEALINGS IN THE SOFTWARE.
2828
//
2929

30-
/// Errors that can occur during code block extraction
30+
/// Errors that can occur during code block extraction from markdown
3131
package enum CodeBlockExtractorError: Error {
32+
/// The extractor instance has already been used and cannot be reused
3233
case alreadyUsed
3334
}

Sources/DocumentationHarness/DocumentationTestHarness.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import SwiftParser
3232
import SwiftSyntax
3333
import Testing
3434

35-
/// Harness for extracting and testing documentation code examples
35+
/// Test harness for extracting and validating Swift code examples from documentation
3636
package struct DocumentationTestHarness {
3737
/// Default file extensions for documentation files
3838
internal static let defaultPathExtensions = ["md"]
@@ -41,6 +41,11 @@ package struct DocumentationTestHarness {
4141
private let fileSearcher: any FileSearcher
4242
private let codeBlocksFrom: CodeBlockExtractor
4343

44+
/// Creates a new documentation test harness
45+
/// - Parameters:
46+
/// - codeValidator: Validator for Swift code syntax (defaults to CodeSyntaxValidator)
47+
/// - fileSearcher: File system searcher (defaults to FileManager.default)
48+
/// - codeBlocksFrom: Function to extract code blocks from content
4449
package init(
4550
codeValidator: any SyntaxValidator = CodeSyntaxValidator(),
4651
fileSearcher: any FileSearcher = FileManager.default,
@@ -51,7 +56,13 @@ package struct DocumentationTestHarness {
5156
self.codeBlocksFrom = codeBlocksFrom
5257
}
5358

54-
/// Validates all code examples in all documentation files
59+
/// Validates all Swift code examples found in documentation files
60+
/// - Parameters:
61+
/// - relativePaths: Array of relative paths to search for documentation
62+
/// - projectRoot: Root URL of the project
63+
/// - pathExtensions: File extensions to search for (defaults to ["md"])
64+
/// - Returns: Array of validation results for all code blocks found
65+
/// - Throws: FileSearchError if file operations fail
5566
package func validate(
5667
relativePaths: [String], atProjectRoot projectRoot: URL,
5768
withPathExtensions pathExtensions: [String] = Self.defaultPathExtensions
@@ -73,7 +84,10 @@ package struct DocumentationTestHarness {
7384
return allResults
7485
}
7586

76-
/// Validates code examples in a specific file
87+
/// Validates all Swift code examples in a specific documentation file
88+
/// - Parameter fileURL: URL of the file to validate
89+
/// - Returns: Array of validation results for code blocks in the file
90+
/// - Throws: Error if file cannot be read or parsed
7791
package func validateExamplesInFile(_ fileURL: URL) throws -> [ValidationResult] {
7892
// let fullPath = try resolveFilePath(filePath)
7993
let content = try String(contentsOf: fileURL)

Sources/DocumentationHarness/FileSearchError.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@
2929

3030
import Foundation
3131

32+
/// Errors that can occur during file searching operations
3233
package enum FileSearchError: Error, LocalizedError {
34+
/// Cannot access the specified path
3335
case cannotAccessPath(String, underlying: any Error)
36+
/// Cannot read the contents of a directory
3437
case cannotReadDirectory(String, underlying: any Error)
38+
/// An unknown error occurred
3539
case unknownError(any Error)
3640

41+
/// Human-readable description of the file search error
3742
package var errorDescription: String? {
3843
switch self {
3944
case .cannotAccessPath(let path, let underlying):

Sources/DocumentationHarness/FileSearcher.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@
2929

3030
package import Foundation
3131

32+
/// Protocol for searching files in directories
3233
package protocol FileSearcher {
34+
/// Searches a directory for files with specific extensions
35+
/// - Parameters:
36+
/// - path: The directory URL to search
37+
/// - pathExtensions: Array of file extensions to search for (without dots)
38+
/// - Returns: Array of URLs for matching files
39+
/// - Throws: FileSearchError if search fails
3340
func searchDirectory(at path: URL, forExtensions pathExtensions: [String]) throws(FileSearchError)
3441
-> [URL]
3542
}

Sources/DocumentationHarness/SyntaxValidator.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
// OTHER DEALINGS IN THE SOFTWARE.
2828
//
2929

30+
/// Protocol for validating Swift code syntax
3031
package protocol SyntaxValidator {
32+
/// Validates the syntax of Swift code
33+
/// - Parameter code: The Swift code to validate
34+
/// - Throws: ValidationError if validation fails
3135
func validateCode(_ code: String) throws(ValidationError)
3236
}
3337
extension SyntaxValidator {

Sources/DocumentationHarness/TestType.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929

3030
import Foundation
3131

32+
/// Represents the type of test performed on a code block
3233
package enum TestType {
34+
/// Code was parsed for syntax validation only
3335
case parsing
36+
/// Code was executed (compiled and run)
3437
case execution
38+
/// Code validation was skipped
3539
case skipped
3640
}

Sources/DocumentationHarness/ValidationError.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929

3030
import Foundation
3131

32-
/// Process execution errors
32+
/// Errors that can occur during process execution
3333
package enum ProcessError: Error, Sendable {
3434
/// Package.swift validation failed
3535
case packageValidationFailed
3636
/// Package validation setup failed
3737
case setupError(any Error)
3838
}
3939

40-
/// Error type for Swift syntax validation failures
40+
/// Errors that can occur during Swift code validation
4141
package enum ValidationError: Error, Sendable {
4242
/// Syntax parsing detected errors in the code
4343
case syntaxError
@@ -51,7 +51,7 @@ package enum ValidationError: Error, Sendable {
5151
/// Unexpected error during validation
5252
case unexpectedError(any Error)
5353

54-
/// Reasons why code should be skipped
54+
/// Reasons why code validation should be skipped
5555
package enum SkipReason: Equatable, Sendable {
5656
/// Package.swift or dependency configuration
5757
case packageFile
@@ -65,7 +65,7 @@ package enum ValidationError: Error, Sendable {
6565
case emptyOrTooShort
6666
}
6767

68-
/// Returns a human-readable description of the error
68+
/// Human-readable description of the validation error
6969
package var localizedDescription: String {
7070
switch self {
7171
case .unexpectedError(let error):

Sources/DocumentationHarness/ValidationResult.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,31 @@
2929

3030
package import Foundation
3131

32+
/// Result of validating a code block from documentation
3233
package struct ValidationResult {
3334
internal let parameters: any ValidationParameters
35+
/// The type of test that was performed
3436
package let testType: TestType
37+
/// Any error that occurred during validation (nil if successful)
3538
package let error: ValidationError?
3639

37-
/// Returns true if validation was successful (no error)
40+
/// Whether the validation was successful (no error occurred)
3841
package var isSuccess: Bool {
3942
error == nil
4043
}
4144

45+
/// Whether the validation was skipped
4246
package var isSkipped: Bool {
4347
error?.isSkipped ?? false
4448
}
4549

4650
// MARK: - Convenience Properties
51+
/// The URL of the file containing the validated code
4752
package var fileURL: URL {
4853
parameters.fileURL
4954
}
5055

56+
/// The line number where the code block starts
5157
package var lineNumber: Int {
5258
parameters.lineNumber
5359
}

0 commit comments

Comments
 (0)