Skip to content

Commit b9b8e82

Browse files
committed
ValidateDocumentationComments - allow throws doc comments for rethrows functions
1 parent 6933505 commit b9b8e82

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Sources/SwiftFormat/Rules/ValidateDocumentationComments.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,13 @@ public final class ValidateDocumentationComments: SyntaxLintRule {
131131
throwsDescription: Paragraph?,
132132
node: DeclSyntax
133133
) {
134-
// If a function is marked as `rethrows`, it doesn't have any errors of its
135-
// own that should be documented. So only require documentation for
136-
// functions marked `throws`.
134+
// Documentation is required for functions marked as `throws`.
135+
// For functions marked as `rethrows`, documentation is not enforced
136+
// since they don’t introduce new errors of their own.
137+
// However, it can still be included if needed.
137138
let needsThrowsDesc = throwsOrRethrowsKeyword?.tokenKind == .keyword(.throws)
138139

139-
if !needsThrowsDesc && throwsDescription != nil {
140+
if throwsOrRethrowsKeyword?.tokenKind == nil && throwsDescription != nil {
140141
diagnose(
141142
.removeThrowsComment(funcName: name),
142143
on: throwsOrRethrowsKeyword ?? node.firstToken(viewMode: .sourceAccurate)

Tests/SwiftFormatTests/Rules/ValidateDocumentationCommentsTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ final class ValidateDocumentationCommentsTests: LintOrFormatRuleTestCase {
9595
findings: [
9696
FindingSpec("1️⃣", message: "remove the 'Throws:' sections of 'doesNotThrow'; it does not throw any errors"),
9797
FindingSpec("2️⃣", message: "add a 'Throws:' section to document the errors thrown by 'doesThrow'"),
98-
FindingSpec("3️⃣", message: "remove the 'Throws:' sections of 'doesRethrow'; it does not throw any errors"),
9998
]
10099
)
101100
}

0 commit comments

Comments
 (0)