|
11 | 11 | //===----------------------------------------------------------------------===// |
12 | 12 |
|
13 | 13 | import Foundation |
| 14 | +import Markdown |
14 | 15 | import SwiftSyntax |
15 | 16 |
|
16 | 17 | #if os(macOS) |
@@ -91,14 +92,20 @@ public final class BeginDocumentationCommentWithOneLineSummary: SyntaxLintRule { |
91 | 92 |
|
92 | 93 | /// Diagnose documentation comments that don't start with one sentence summary. |
93 | 94 | private func diagnoseDocComments(in decl: DeclSyntax) { |
| 95 | + // Extract the summary from a documentation comment, if it exists, and strip |
| 96 | + // out any inline code segments (which shouldn't be considered when looking |
| 97 | + // for the end of a sentence). |
| 98 | + var inlineCodeRemover = InlineCodeRemover() |
94 | 99 | guard |
95 | 100 | let docComment = DocumentationComment(extractedFrom: decl), |
96 | | - let briefSummary = docComment.briefSummary |
| 101 | + let briefSummary = docComment.briefSummary, |
| 102 | + let noInlineCodeSummary = inlineCodeRemover.visit(briefSummary) as? Paragraph |
97 | 103 | else { return } |
98 | 104 |
|
99 | 105 | // For the purposes of checking the sentence structure of the comment, we can operate on the |
100 | 106 | // plain text; we don't need any of the styling. |
101 | | - let trimmedText = briefSummary.plainText.trimmingCharacters(in: .whitespacesAndNewlines) |
| 107 | + let trimmedText = noInlineCodeSummary.plainText |
| 108 | + .trimmingCharacters(in: .whitespacesAndNewlines) |
102 | 109 | let (commentSentences, trailingText) = sentences(in: trimmedText) |
103 | 110 | if commentSentences.count == 0 { |
104 | 111 | diagnose(.terminateSentenceWithPeriod(trimmedText), on: decl) |
@@ -231,3 +238,9 @@ extension Finding.Message { |
231 | 238 | "add a blank comment line after this sentence: \"\(text)\"" |
232 | 239 | } |
233 | 240 | } |
| 241 | + |
| 242 | +struct InlineCodeRemover: MarkupRewriter { |
| 243 | + mutating func visitInlineCode(_ inlineCode: InlineCode) -> Markup? { |
| 244 | + nil |
| 245 | + } |
| 246 | +} |
0 commit comments