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
30 changes: 30 additions & 0 deletions src/Microdown-Rules/MicCodeIndentationChecker.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"
I check that code blocks use tabs for indentation instead of spaces.
A line that starts with a space character is considered incorrectly indented.
"
Class {
#name : 'MicCodeIndentationChecker',
#superclass : 'MicChecker',
#category : 'Microdown-Rules-CodeIndetation',
#package : 'Microdown-Rules',
#tag : 'CodeIndetation'
}
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' }
MicCodeIndentationChecker >> visitCode: aMicCode [
| lines |
lines := aMicCode body lines.
lines do: [ :line |
line isEmpty ifFalse: [
"verify if the line begin with space"
(line first = Character space) ifTrue: [
results add: (MicCodeIndentationResult new
micElement: aMicCode;
inFile: aMicCode fromFile;
detail: line;
yourself
)
]
]
]
]
53 changes: 53 additions & 0 deletions src/Microdown-Rules/MicCodeIndentationCheckerTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Class {
#name : 'MicCodeIndentationCheckerTest',
#superclass : 'TestCase',
#instVars : [
'fileSystem',
'checker'
],
#category : 'Microdown-Rules-CodeIndetation',
#package : 'Microdown-Rules',
#tag : 'CodeIndetation'
}

{ #category : 'running' }
MicCodeIndentationCheckerTest >> generateFilesystemExample [
| file |
"incorrect cases - space instead of tabs"
file := fileSystem workingDirectory / 'indentationWrong.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: '```
foo
self
`````'
].
"correct cases - tabs"
file := fileSystem workingDirectory / 'indentationCorrect.md'.
file writeStreamDo: [ :stream |
stream nextPutAll: '```
foo
self
````' ].
]

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

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

{ #category : 'tests' }
MicCodeIndentationCheckerTest >> testIndentationCorrect [
checker checkProject: fileSystem / 'indentationCorrect.md'.
self assert: checker isOkay.
]

{ #category : 'tests' }
MicCodeIndentationCheckerTest >> testIndentationWrongDetected [
checker checkProject: fileSystem / 'indentationWrong.md'.
self deny: checker isOkay.
self assert: checker results size equals: 1.
]
31 changes: 31 additions & 0 deletions src/Microdown-Rules/MicCodeIndentationResult.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Class {
#name : 'MicCodeIndentationResult',
#superclass : 'MicAbstractResult',
#instVars : [
'detail'
],
#category : 'Microdown-Rules-CodeIndetation',
#package : 'Microdown-Rules',
#tag : 'CodeIndetation'
}

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

^ detail
]

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

detail := anObject
]

{ #category : 'accessing' }
MicCodeIndentationResult >> explanation [
^ 'Text: "' , micElement body
, '" in file' , fileReference fullName
, ' contains a mistake: line ['
, detail
, '] should use tabs instead of spaces for indentation.'
]