Skip to content

Commit f0ab30a

Browse files
dduangithub-actions[bot]
authored andcommitted
Fix returns/throws description with empty first line
Closes #213
1 parent de9586f commit f0ab30a

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
## 0.5.0
44

5-
### Improvement (breaking change?)
5+
### New
66

77
- `drstring check` now reports each problem it finds with a file path, line, and column, as apposed to before,
88
where all problems for a specific signature are grouped together. Each type of problem has a custom column
99
position to best indicate which part of the docstring it relates to.
1010
- `drstring extract`'s output for existing docstrings gained a new field `relativeLineNumber` for each
1111
"entry".
12+
13+
### Bug fixes
1214
- In grouped parameter style, spacing between the dash `-` and the parameter was not checked before. From this
1315
release on, any spacing except a single space is deemed problematic. (#225)
16+
- If documentation for throws and returns starts on the second line, previously this was considered
17+
problematic. But it's pretty common to start on the next line. This bug has been fixed. (#213)
1418

1519
## 0.4.3
1620

Sources/Critic/Validating.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ func findReturnsProblems(
142142
column += 1
143143
}
144144

145-
if let postColonLead = returnsDoc.description.first?.lead {
146-
if postColonLead != " " {
147-
result.append((.init(lineNumber, column), .spaceAfterColon(keywordText, postColonLead)))
145+
if let firstLine = returnsDoc.description.first {
146+
if firstLine.lead != " " && !firstLine.text.isEmpty {
147+
result.append((.init(lineNumber, column), .spaceAfterColon(keywordText, firstLine.lead)))
148148
}
149149

150-
column += postColonLead.count
150+
column += firstLine.lead.count
151151
}
152152

153153
if alignAfterColon {
@@ -225,12 +225,12 @@ func findThrowsProblems(
225225
column += 1
226226
}
227227

228-
if let postColonLead = throwsDoc.description.first?.lead {
229-
if postColonLead != " " {
230-
result.append((.init(lineNumber, column), .spaceAfterColon(keywordText, postColonLead)))
228+
if let firstLine = throwsDoc.description.first {
229+
if firstLine.lead != " " && !firstLine.text.isEmpty {
230+
result.append((.init(lineNumber, column), .spaceAfterColon(keywordText, firstLine.lead)))
231231
}
232232

233-
column += postColonLead.count
233+
column += firstLine.lead.count
234234
}
235235

236236
if alignAfterColon {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// CHECK-NOT: warning
2+
/// - Throws:
3+
/// - Error1 when x
4+
/// - Error2 when y
5+
func f() throws {}
6+
7+
// CHECK-NOT: warning
8+
/// - Returns:
9+
/// - 1 when x
10+
/// - 0 when y
11+
func g() -> Int {}

Tests/DrStringCoreTests/ProblemCheckingTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,8 @@ final class ProblemCheckingTests: XCTestCase {
135135
runTest(fileName: "positional", alignAfterColon: [.parameters, .returns, .throws],
136136
needsSeparation: [.description, .parameters]))
137137
}
138+
139+
func testThrowsWithDescriptionStartingFromNextLine() throws {
140+
XCTAssert(runTest(fileName: "throwDescriptionNextLine", expectEmpty: true))
141+
}
138142
}

Tests/DrStringCoreTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ extension ProblemCheckingTests {
7878
("testRedundantKeywordsPathsOnly", testRedundantKeywordsPathsOnly),
7979
("testSeparateLineInThrowsIsNotTreatedAsContinuedBody", testSeparateLineInThrowsIsNotTreatedAsContinuedBody),
8080
("testSeparateParameterStyle", testSeparateParameterStyle),
81+
("testThrowsWithDescriptionStartingFromNextLine", testThrowsWithDescriptionStartingFromNextLine),
8182
("testUppercaseKeywords", testUppercaseKeywords),
8283
("testWhateverParameterStyle", testWhateverParameterStyle),
8384
]

0 commit comments

Comments
 (0)