Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/Microdown-Rules/MicFigSectTableResult.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Class {
#name : 'MicFigSectTableResult',
#superclass : 'MicAbstractResult',
#instVars : [
'detail'
],
#category : 'Microdown-Rules-References',
#package : 'Microdown-Rules',
#tag : 'References'
}

{ #category : 'accessing' }
MicFigSectTableResult >> detail [

^ detail
]

{ #category : 'accessing' }
MicFigSectTableResult >> detail: anObject [

detail := anObject
]

{ #category : 'accessing' }
MicFigSectTableResult >> explanation [
^ 'Text: "' , micElement bodyString
, '" in file' , fileReference fullName
, ' contains a mistake: ['
, detail
, '] should be capitalized as ['
, detail capitalized , '].'
]
74 changes: 74 additions & 0 deletions src/Microdown-Rules/MicReferencesChecker.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"
I check that references to figures, sections and tables are correctly capitalized before an anchor.
In Microdown, references should be written as:
Figure *@figureExample@*
Section *@sectionExample@*
Table *@tableExample*

The following are incorrect and will be flagged:
figure *@figureExample@* (lowercase)
the figure *@figureExample@* (proceded by 'the')
section *@sectionExample@* (lowercase)
"
Class {
#name : 'MicReferencesChecker',
#superclass : 'MicChecker',
#category : 'Microdown-Rules-References',
#package : 'Microdown-Rules',
#tag : 'References'
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a class comment that explains what this checker is about

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll add class comment for this checker.

{ #category : 'visiting' }
MicReferencesChecker >> visitParagraph: aMicParagraph [
| children |
children := aMicParagraph children.
1 to: children size - 1 do: [ :index |
| child nextChild |
child := children at: index.
nextChild := children at: index + 1.
(nextChild isKindOf: MicAnchorReferenceBlock ) ifTrue: [
(child isKindOf: MicTextBlock ) ifTrue: [
| words lastWord foundThe |
words := child bodyString substrings.
words isEmpty ifFalse:[
lastWord := words last.
foundThe := false.
"verify the figure/section/table"
#('figure' 'section' 'table') do: [ :ref |
(lastWord asLowercase = ref) ifTrue: [
words size > 1 ifTrue: [
| prevWord |
prevWord := words at: words size - 1.
(prevWord asLowercase = 'the') ifTrue: [
foundThe := true.
results add: (MicFigSectTableResult new
micElement: child;
inFile: aMicParagraph fromFile;
detail: 'the ' , lastWord;
yourself
)
]
]
]

].
"check figure/section/table"
foundThe ifFalse: [
#('figure' 'table' 'section') do: [ :ref |
(lastWord = ref) ifTrue: [
results add: (MicFigSectTableResult new
micElement: child;
inFile: aMicParagraph fromFile;
detail: lastWord;
yourself
)
]
]


]
]
]
]
]
]
155 changes: 155 additions & 0 deletions src/Microdown-Rules/MicReferencesCheckerTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
Class {
#name : 'MicReferencesCheckerTest',
#superclass : 'TestCase',
#instVars : [
'fileSystem',
'checker'
],
#category : 'Microdown-Rules-References',
#package : 'Microdown-Rules',
#tag : 'References'
}

{ #category : 'running' }
MicReferencesCheckerTest >> generateFilesystemExample [
| file |
file := fileSystem workingDirectory / 'figureWrong.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'figure *@figbla@*'
].
file := fileSystem workingDirectory / 'tableWrong.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'table *@tablab@*'
].
file := fileSystem workingDirectory / 'sectionWrong.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'section *@secbla@*'
].
file := fileSystem workingDirectory / 'theFigureWrong.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'the figure *@figbla@*'
].
file := fileSystem workingDirectory / 'theSectionWrong.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'the section *@seclab@*'
].
file := fileSystem workingDirectory / 'theTableWrong.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'the table *@tabbla@*'
].
file := fileSystem workingDirectory / 'figureCorrect.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'Figure *@figbla@*'
].
file := fileSystem workingDirectory / 'sectionCorrect.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'Section *@secbla@*'
].
file := fileSystem workingDirectory / 'tableCorrect.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'Table *@tabbla@*'
].
file := fileSystem workingDirectory / 'noAnchor.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: 'figure without anchor'
].
]

{ #category : 'running' }
MicReferencesCheckerTest >> setUp [
super setUp.

fileSystem := FileSystem memory.
self generateFilesystemExample.
checker := MicReferencesChecker new.
]

{ #category : 'running' }
MicReferencesCheckerTest >> testFigureCorrect [
checker checkProject: fileSystem / 'figureCorrect.md'.
self assert: checker isOkay.


]

{ #category : 'running' }
MicReferencesCheckerTest >> testFigureExplanation [
checker checkProject: fileSystem / 'figureWrong.md'.
self assert: checker results first explanation
equals: 'Text: "figure " in file/figureWrong.md contains a mistake: [figure] should be capitalized as [Figure].'.

]

{ #category : 'running' }
MicReferencesCheckerTest >> testFigureLowercaseDetected [
checker checkProject: fileSystem / 'figureWrong.md'.
self deny: checker isOkay.
self assert: checker results size equals: 1.
self assert: checker results first detail equals: 'figure'.

]

{ #category : 'running' }
MicReferencesCheckerTest >> testSectionCorrect [
checker checkProject: fileSystem / 'sectionCorrect.md'.
self assert: checker isOkay.


]

{ #category : 'running' }
MicReferencesCheckerTest >> testSectionLowercaseDetected [
checker checkProject: fileSystem / 'sectionWrong.md'.
self deny: checker isOkay.
self assert: checker results size equals: 1.
self assert: checker results first detail equals: 'section'.

]

{ #category : 'running' }
MicReferencesCheckerTest >> testTableCorrect [
checker checkProject: fileSystem / 'tableCorrect.md'.
self assert: checker isOkay.


]

{ #category : 'running' }
MicReferencesCheckerTest >> testTableLowercaseDetected [
checker checkProject: fileSystem / 'tableWrong.md'.
self deny: checker isOkay.
self assert: checker results size equals: 1.
self assert: checker results first detail equals: 'table'.

]

{ #category : 'running' }
MicReferencesCheckerTest >> testTextWithoutAnchor [
checker checkProject: fileSystem / 'noAnchor.md'.
self assert: checker isOkay.

]

{ #category : 'running' }
MicReferencesCheckerTest >> testTheFigureDetected [
checker checkProject: fileSystem / 'theFigureWrong.md'.
self deny: checker isOkay.
self assert: checker results first detail equals: 'the figure'.

]

{ #category : 'running' }
MicReferencesCheckerTest >> testTheSectionDetected [
checker checkProject: fileSystem / 'theSectionWrong.md'.
self deny: checker isOkay.
self assert: checker results first detail equals: 'the section'.

]

{ #category : 'running' }
MicReferencesCheckerTest >> testTheTableDetected [
checker checkProject: fileSystem / 'theTableWrong.md'.
self deny: checker isOkay.
self assert: checker results first detail equals: 'the table'.

]