Skip to content

Commit 17b3082

Browse files
committed
Another checker! for the code block finishing or not with a period
1 parent b70c48b commit 17b3082

15 files changed

+229
-43
lines changed

src/Microdown-BookTester/MicChecker.class.st

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ Class {
1818
#tag : 'Core'
1919
}
2020

21+
{ #category : 'accessing' }
22+
MicChecker >> checkProject: aFileReference [
23+
24+
| collector |
25+
collector := self fileCollectorForMainFileReference: aFileReference.
26+
collector visitedFilesAsDOM do: [ :each | each accept: self ]
27+
]
28+
2129
{ #category : 'accessing' }
2230
MicChecker >> fileCollectorForMainFileReference: aFileReference [
2331

@@ -37,6 +45,11 @@ MicChecker >> initialize [
3745
results := OrderedCollection new.
3846
]
3947

48+
{ #category : 'testing' }
49+
MicChecker >> isOkay [
50+
^ results isEmpty
51+
]
52+
4053
{ #category : 'accessing' }
4154
MicChecker >> reportWriter [
4255

src/Microdown-BookTester/MicCodeBlockValidator.class.st

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ MicCodeBlockValidator class >> isAbstract [
2525
^ false
2626
]
2727

28-
{ #category : 'main API' }
29-
MicCodeBlockValidator >> checkProject: aFileReference [
30-
31-
| collector |
32-
collector := self fileCollectorForMainFileReference: aFileReference.
33-
collector visitedFiles do: [ :each | self start: each ]
34-
]
35-
3628
{ #category : 'initialization' }
3729
MicCodeBlockValidator >> collectStrategies [
3830

src/Microdown-BookTester/MicReferenceChecker.class.st

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,6 @@ MicReferenceChecker >> isOk [
214214
references allSatisfy: [ :each | self hasAlreadyDefinedAs: each ] ]
215215
]
216216

217-
{ #category : 'testing' }
218-
MicReferenceChecker >> isOkay [
219-
220-
^ results isEmpty
221-
]
222-
223217
{ #category : 'reporting' }
224218
MicReferenceChecker >> report [
225219

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Class {
22
#name : 'MicElementOfHeaderIsNotCapitalizedReport',
33
#superclass : 'MicReport',
4-
#category : 'Microdown-Rules-Capitalization',
4+
#category : 'Microdown-Rules-CapitalizationUnderway',
55
#package : 'Microdown-Rules',
6-
#tag : 'Capitalization'
6+
#tag : 'CapitalizationUnderway'
77
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Class {
22
#name : 'MicElementOfHeaderIsWronglyCapitalizedReport',
33
#superclass : 'MicReport',
4-
#category : 'Microdown-Rules-Capitalization',
4+
#category : 'Microdown-Rules-CapitalizationUnderway',
55
#package : 'Microdown-Rules',
6-
#tag : 'Capitalization'
6+
#tag : 'CapitalizationUnderway'
77
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Class {
22
#name : 'MicFirstElementOfHeaderIsNotCapitalizedReport',
33
#superclass : 'MicReport',
4-
#category : 'Microdown-Rules-Capitalization',
4+
#category : 'Microdown-Rules-CapitalizationUnderway',
55
#package : 'Microdown-Rules',
6-
#tag : 'Capitalization'
6+
#tag : 'CapitalizationUnderway'
77
}

src/Microdown-Rules/MicHeaderCapitalizationRule.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Class {
77
'unlowercasableText',
88
'ifAddDefaultNotCapitalized'
99
],
10-
#category : 'Microdown-Rules-Capitalization',
10+
#category : 'Microdown-Rules-CapitalizationUnderway',
1111
#package : 'Microdown-Rules',
12-
#tag : 'Capitalization'
12+
#tag : 'CapitalizationUnderway'
1313
}
1414

1515
{ #category : 'stop words' }
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Class {
2+
#name : 'MicLastPeriodInCodeChecker',
3+
#superclass : 'MicChecker',
4+
#instVars : [
5+
'codeShouldEndWithPeriod'
6+
],
7+
#category : 'Microdown-Rules-CodeLastPeriod',
8+
#package : 'Microdown-Rules',
9+
#tag : 'CodeLastPeriod'
10+
}
11+
12+
{ #category : 'visiting' }
13+
MicLastPeriodInCodeChecker >> checkExtraPeriodIn: aMicCodeBlock [
14+
15+
(aMicCodeBlock body trimRight last = $.)
16+
ifTrue: [ results add: (MicPeriodInCodeResult new
17+
micElement: aMicCodeBlock;
18+
inFile: aMicCodeBlock fromFile;
19+
codeShouldEndWithPeriod: codeShouldEndWithPeriod
20+
) ]
21+
22+
]
23+
24+
{ #category : 'visiting' }
25+
MicLastPeriodInCodeChecker >> checkMissingPeriodIn: aMicCodeBlock [
26+
27+
aMicCodeBlock body trimRight last = $. ifFalse: [
28+
results add: (MicPeriodInCodeResult new
29+
micElement: aMicCodeBlock;
30+
inFile: aMicCodeBlock fromFile;
31+
codeShouldEndWithPeriod: codeShouldEndWithPeriod) ]
32+
]
33+
34+
{ #category : 'visiting' }
35+
MicLastPeriodInCodeChecker >> identifyExtraLastPeriod [
36+
37+
codeShouldEndWithPeriod := false
38+
]
39+
40+
{ #category : 'visiting' }
41+
MicLastPeriodInCodeChecker >> identifyMissingLastPeriod [
42+
43+
codeShouldEndWithPeriod := true
44+
]
45+
46+
{ #category : 'visiting' }
47+
MicLastPeriodInCodeChecker >> visitCode: aCodeBlockElement [
48+
49+
codeShouldEndWithPeriod
50+
ifTrue: [ self checkMissingPeriodIn: aCodeBlockElement ]
51+
ifFalse: [ self checkExtraPeriodIn: aCodeBlockElement ]
52+
]
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Class {
2+
#name : 'MicLastPeriodInCodeCheckerTest',
3+
#superclass : 'TestCase',
4+
#instVars : [
5+
'fileSystem',
6+
'checker'
7+
],
8+
#category : 'Microdown-Rules-CodeLastPeriod',
9+
#package : 'Microdown-Rules',
10+
#tag : 'CodeLastPeriod'
11+
}
12+
13+
{ #category : 'running' }
14+
MicLastPeriodInCodeCheckerTest >> generateFilesystemExample [
15+
16+
| file |
17+
file := fileSystem workingDirectory / 'codeEndingWithPeriod.md'.
18+
file writeStreamDo: [ :stream |
19+
stream nextPutAll: '
20+
21+
Authors may want to detect useless period as in the following code snippet
22+
23+
```
24+
setX: xInt setY: yInt
25+
26+
x := xInt.
27+
y := yInt.
28+
```
29+
' ].
30+
31+
file := fileSystem workingDirectory / 'codeNotEndingWithPeriod.md'.
32+
file writeStreamDo: [ :stream |
33+
stream nextPutAll: '
34+
35+
Here the code does not a useless period.
36+
```
37+
setX: xInt setY: yInt
38+
39+
x := xInt.
40+
y := yInt
41+
```
42+
' ]
43+
]
44+
45+
{ #category : 'running' }
46+
MicLastPeriodInCodeCheckerTest >> setUp [
47+
48+
super setUp.
49+
fileSystem := FileSystem memory.
50+
self generateFilesystemExample.
51+
52+
checker := MicLastPeriodInCodeChecker new.
53+
54+
]
55+
56+
{ #category : 'tests - missing period' }
57+
MicLastPeriodInCodeCheckerTest >> testCheckerChecksCorrectlyMissingExtraPeriod [
58+
"may be the author wants all the code to finish with an extra period.
59+
so we configure the checker to do so."
60+
61+
checker identifyMissingLastPeriod.
62+
checker checkProject: fileSystem / 'codeEndingWithPeriod.md'.
63+
self assert: checker isOkay.
64+
65+
]
66+
67+
{ #category : 'tests - extra period' }
68+
MicLastPeriodInCodeCheckerTest >> testCheckerChecksCorrectlyNoExtraPeriod [
69+
70+
checker identifyExtraLastPeriod.
71+
checker checkProject: fileSystem / 'codeNotEndingWithPeriod.md'.
72+
self assert: checker isOkay
73+
]
74+
75+
{ #category : 'tests - extra period' }
76+
MicLastPeriodInCodeCheckerTest >> testCheckerIdentifyCorrectlyExtraPeriod [
77+
78+
checker identifyExtraLastPeriod.
79+
checker checkProject: fileSystem / 'codeEndingWithPeriod.md'.
80+
self deny: checker isOkay.
81+
82+
self assert: checker results first explanation equals: 'Text: "setX: xInt setY: yInt
83+
84+
x := xInt.
85+
y := yInt." in file/codeEndingWithPeriod.md contains a mistake: It should not be terminated with a period (.).'
86+
]
87+
88+
{ #category : 'tests - missing period' }
89+
MicLastPeriodInCodeCheckerTest >> testCheckerIdentifyCorrectlyMissingExtraPeriod [
90+
91+
"may be the author wants all the code to finish with an extra period.
92+
so we configure the checker to do so."
93+
94+
checker identifyMissingLastPeriod.
95+
checker checkProject: fileSystem / 'codeNotEndingWithPeriod.md'.
96+
self deny: checker isOkay.
97+
98+
self
99+
assert: checker results first explanation
100+
equals:
101+
'Text: "setX: xInt setY: yInt
102+
103+
x := xInt.
104+
y := yInt" in file/codeNotEndingWithPeriod.md contains a mistake: It should be terminated with a period (.).'
105+
]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Class {
2+
#name : 'MicPeriodInCodeResult',
3+
#superclass : 'MicResult',
4+
#instVars : [
5+
'micElement',
6+
'fileReference',
7+
'codeShouldEndWithPeriod'
8+
],
9+
#category : 'Microdown-Rules-CodeLastPeriod',
10+
#package : 'Microdown-Rules',
11+
#tag : 'CodeLastPeriod'
12+
}
13+
14+
{ #category : 'accessing' }
15+
MicPeriodInCodeResult >> codeShouldEndWithPeriod: aBoolean [
16+
codeShouldEndWithPeriod := aBoolean
17+
]
18+
19+
{ #category : 'explanation' }
20+
MicPeriodInCodeResult >> explanation [
21+
22+
^ 'Text: "' , micElement body , '" in file' , fileReference fullName , ' contains a mistake: It should'
23+
, (codeShouldEndWithPeriod
24+
ifFalse: [ ' not ' ]
25+
ifTrue: [ ' ' ]) , 'be terminated with a period (.).'
26+
]
27+
28+
{ #category : 'accessing' }
29+
MicPeriodInCodeResult >> inFile: aFileReference [
30+
fileReference := aFileReference
31+
]
32+
33+
{ #category : 'accessing' }
34+
MicPeriodInCodeResult >> micElement [
35+
36+
^ micElement
37+
]
38+
39+
{ #category : 'accessing' }
40+
MicPeriodInCodeResult >> micElement: anObject [
41+
42+
micElement := anObject
43+
]

0 commit comments

Comments
 (0)