Skip to content

Commit 79e96e3

Browse files
committed
Merge PR #128 from nblockchain/wip/fixBugsReportedInCommitMsg
FileConventions,commitlint: partial fix for #120.
2 parents 138844d + 6cb6d10 commit 79e96e3

File tree

6 files changed

+151
-80
lines changed

6 files changed

+151
-80
lines changed

commitlint/plugins.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,26 @@ test("body-paragraph-line-min-length6", () => {
410410
expect(bodyParagraphLineMinLength6.status).toBe(0);
411411
});
412412

413+
test("body-paragraph-line-min-length7", () => {
414+
let commitMsgThatSubceedsBodyMinLineLengthButIsLegit =
415+
"Fixed bug (a title of less than 50 chars)" +
416+
"\n\n" +
417+
"These were the steps to reproduce:\n" +
418+
"Do foo.\n" +
419+
"\n" +
420+
"Current results:\n" +
421+
"Bar happens.\n" +
422+
"\n" +
423+
"Expected results:\n" +
424+
"Baz happens.";
425+
426+
let bodyParagraphLineMinLength7 = runCommitLintOnMsg(
427+
commitMsgThatSubceedsBodyMinLineLengthButIsLegit
428+
);
429+
430+
expect(bodyParagraphLineMinLength7.status).toBe(0);
431+
});
432+
413433
test("commit-hash-alone1", () => {
414434
let commitMsgWithCommitUrl =
415435
"foo: this is only a title" +

commitlint/plugins.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ export abstract class Plugins {
430430
for (let paragraph of paragraphs) {
431431
let lines = paragraph.split(/\r?\n/);
432432
let inBigBlock = false;
433+
434+
// NOTE: we don't iterate over the last line, on purpose
433435
for (let i = 0; i < lines.length - 1; i++) {
434436
let line = lines[i];
435437

@@ -441,9 +443,10 @@ export abstract class Plugins {
441443
continue;
442444
}
443445

444-
let nextLine = lines[i + 1];
445-
446446
if (line.length < paragraphLineMinLength) {
447+
// this ref doesn't go out of bounds because we didn't iter on last line
448+
let nextLine = lines[i + 1];
449+
447450
let isUrl =
448451
Helpers.isValidUrl(line) ||
449452
Helpers.isValidUrl(nextLine);
@@ -455,7 +458,16 @@ export abstract class Plugins {
455458
nextWordLength + line.length + 1 >
456459
paragraphLineMaxLength;
457460

458-
if (!isUrl && !lineIsFooterNote && !isNextWordTooLong) {
461+
let isLastCharAColonBreak =
462+
line[line.length - 1] === ":" &&
463+
nextLine[0].toUpperCase() == nextLine[0];
464+
465+
if (
466+
!isUrl &&
467+
!lineIsFooterNote &&
468+
!isNextWordTooLong &&
469+
!isLastCharAColonBreak
470+
) {
459471
offence = true;
460472
break;
461473
}

src/FileConventions.Test/FileConventions.Test.fs

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module FileConventions.Test
1+
module FileConventions.Test.RestOfTests
22

33
open System
44
open System.IO
@@ -273,82 +273,6 @@ let HasBinaryContentTest3() =
273273
Assert.That(HasBinaryContent fileInfo, Is.EqualTo false)
274274

275275

276-
[<Test>]
277-
let WrapTextTest1() =
278-
let characterCount = 64
279-
280-
let paragraph =
281-
"This is a very very very very long line with more than 64 characters."
282-
283-
let expectedResult =
284-
"This is a very very very very long line with more than 64"
285-
+ Environment.NewLine
286-
+ "characters."
287-
288-
Assert.That(WrapText paragraph characterCount, Is.EqualTo expectedResult)
289-
290-
[<Test>]
291-
let WrapTextTest2() =
292-
let characterCount = 64
293-
294-
let paragraph =
295-
"This is short line."
296-
+ Environment.NewLine
297-
+ "```"
298-
+ Environment.NewLine
299-
+ "This is a very very very very long line with more than 64 characters inside a code block."
300-
+ Environment.NewLine
301-
+ "```"
302-
303-
let expectedResult = paragraph
304-
305-
Assert.That(WrapText paragraph characterCount, Is.EqualTo expectedResult)
306-
307-
[<Test>]
308-
let WrapTextTest3() =
309-
let characterCount = 64
310-
let tenDigits = "1234567890"
311-
312-
let seventyChars =
313-
tenDigits
314-
+ tenDigits
315-
+ tenDigits
316-
+ tenDigits
317-
+ tenDigits
318-
+ tenDigits
319-
+ tenDigits
320-
321-
let paragraph =
322-
"This is short line referring to [1]."
323-
+ Environment.NewLine
324-
+ "[1] someUrl://"
325-
+ seventyChars
326-
327-
let expectedResult = paragraph
328-
329-
Assert.That(WrapText paragraph characterCount, Is.EqualTo expectedResult)
330-
331-
332-
[<Test>]
333-
let WrapTextTest4() =
334-
let characterCount = 64
335-
336-
let text =
337-
"This is short line."
338-
+ Environment.NewLine
339-
+ Environment.NewLine
340-
+ "This is a very very very very very long line with more than 64 characters."
341-
342-
let expectedResult =
343-
"This is short line."
344-
+ Environment.NewLine
345-
+ Environment.NewLine
346-
+ "This is a very very very very very long line with more than 64"
347-
+ Environment.NewLine
348-
+ "characters."
349-
350-
Assert.That(WrapText text characterCount, Is.EqualTo expectedResult)
351-
352276
[<Test>]
353277

354278
let DetectInconsistentVersionsInGitHubCIWorkflow1() =

src/FileConventions.Test/FileConventions.Test.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11+
<Compile Include="WrapTextTests.fs" />
1112
<Compile Include="FileConventions.Test.fs" />
1213
<Compile Include="Program.fs" />
1314
</ItemGroup>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
module FileConventions.Test.WrapTextTests
2+
3+
open System
4+
5+
open NUnit.Framework
6+
7+
open FileConventions
8+
9+
[<Test>]
10+
let WrapTextTest1() =
11+
let characterCount = 64
12+
13+
let paragraph =
14+
"This is a very very very very long line with more than 64 characters."
15+
16+
let expectedResult =
17+
"This is a very very very very long line with more than 64"
18+
+ Environment.NewLine
19+
+ "characters."
20+
21+
Assert.That(WrapText paragraph characterCount, Is.EqualTo expectedResult)
22+
23+
[<Test>]
24+
let WrapTextTest2() =
25+
let characterCount = 64
26+
27+
let paragraph =
28+
"This is short line."
29+
+ Environment.NewLine
30+
+ "```"
31+
+ Environment.NewLine
32+
+ "This is a very very very very long line with more than 64 characters inside a code block."
33+
+ Environment.NewLine
34+
+ "```"
35+
36+
let expectedResult = paragraph
37+
38+
Assert.That(WrapText paragraph characterCount, Is.EqualTo expectedResult)
39+
40+
[<Test>]
41+
let WrapTextTest3() =
42+
let characterCount = 64
43+
let tenDigits = "1234567890"
44+
45+
let seventyChars =
46+
tenDigits
47+
+ tenDigits
48+
+ tenDigits
49+
+ tenDigits
50+
+ tenDigits
51+
+ tenDigits
52+
+ tenDigits
53+
54+
let paragraph =
55+
"This is short line referring to [1]."
56+
+ Environment.NewLine
57+
+ "[1] someUrl://"
58+
+ seventyChars
59+
60+
let expectedResult = paragraph
61+
62+
Assert.That(WrapText paragraph characterCount, Is.EqualTo expectedResult)
63+
64+
65+
[<Test>]
66+
let WrapTextTest4() =
67+
let characterCount = 64
68+
69+
let text =
70+
"This is short line."
71+
+ Environment.NewLine
72+
+ Environment.NewLine
73+
+ "This is a very very very very very long line with more than 64 characters."
74+
75+
let expectedResult =
76+
"This is short line."
77+
+ Environment.NewLine
78+
+ Environment.NewLine
79+
+ "This is a very very very very very long line with more than 64"
80+
+ Environment.NewLine
81+
+ "characters."
82+
83+
Assert.That(WrapText text characterCount, Is.EqualTo expectedResult)
84+
85+
[<Test>]
86+
let WrapTextTest5() =
87+
let characterCount = 64
88+
89+
let text =
90+
"Fixed bug (a title of less than 50 chars)"
91+
+ Environment.NewLine
92+
+ Environment.NewLine
93+
+ "These were the steps to reproduce:"
94+
+ Environment.NewLine
95+
+ "Do foo."
96+
+ Environment.NewLine
97+
+ Environment.NewLine
98+
+ "Current results:"
99+
+ Environment.NewLine
100+
+ "Bar happens."
101+
+ Environment.NewLine
102+
+ Environment.NewLine
103+
+ "Expected results:"
104+
+ Environment.NewLine
105+
+ "Baz happens."
106+
107+
let expectedResult = text
108+
109+
Assert.That(WrapText text characterCount, Is.EqualTo expectedResult)

src/FileConventions/Library.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ let private WrapParagraph (text: string) (maxCharsPerLine: int) : string =
203203
(wrappedText: string)
204204
(remainingWords: List<Text>)
205205
: string =
206+
207+
let isColonBreak (currentLine: string) (textAfter: Text) =
208+
currentLine.EndsWith ":" && Char.IsUpper textAfter.Text.[0]
209+
206210
match remainingWords with
207211
| [] -> (wrappedText + currentLine).Trim()
208212
| word :: rest ->
@@ -214,6 +218,7 @@ let private WrapParagraph (text: string) (maxCharsPerLine: int) : string =
214218
} when
215219
String.length currentLine + word.Text.Length + 1
216220
<= maxCharsPerLine
221+
&& not(isColonBreak currentLine word)
217222
->
218223
processWords (currentLine + " " + word.Text) wrappedText rest
219224
| _,

0 commit comments

Comments
 (0)