Skip to content

Commit 7be6f1e

Browse files
authored
Merge pull request pillar-markup#1007 from Fanirindrainy/feature/code-indentation
Feature/code indentation
2 parents d501844 + f1e718e commit 7be6f1e

3 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"
2+
I check that code blocks use tabs for indentation instead of spaces.
3+
A line that starts with a space character is considered incorrectly indented.
4+
"
5+
Class {
6+
#name : 'MicCodeIndentationChecker',
7+
#superclass : 'MicChecker',
8+
#category : 'Microdown-Rules-CodeIndetation',
9+
#package : 'Microdown-Rules',
10+
#tag : 'CodeIndetation'
11+
}
12+
13+
{ #category : 'visiting' }
14+
MicCodeIndentationChecker >> visitCode: aMicCode [
15+
| lines |
16+
lines := aMicCode body lines.
17+
lines do: [ :line |
18+
line isEmpty ifFalse: [
19+
"verify if the line begin with space"
20+
(line first = Character space) ifTrue: [
21+
results add: (MicCodeIndentationResult new
22+
micElement: aMicCode;
23+
inFile: aMicCode fromFile;
24+
detail: line;
25+
yourself
26+
)
27+
]
28+
]
29+
]
30+
]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Class {
2+
#name : 'MicCodeIndentationCheckerTest',
3+
#superclass : 'TestCase',
4+
#instVars : [
5+
'fileSystem',
6+
'checker'
7+
],
8+
#category : 'Microdown-Rules-CodeIndetation',
9+
#package : 'Microdown-Rules',
10+
#tag : 'CodeIndetation'
11+
}
12+
13+
{ #category : 'running' }
14+
MicCodeIndentationCheckerTest >> generateFilesystemExample [
15+
| file |
16+
"incorrect cases - space instead of tabs"
17+
file := fileSystem workingDirectory / 'indentationWrong.md'.
18+
file writeStreamDo: [ :stream |
19+
stream nextPutAll: '```
20+
foo
21+
self
22+
`````'
23+
].
24+
"correct cases - tabs"
25+
file := fileSystem workingDirectory / 'indentationCorrect.md'.
26+
file writeStreamDo: [ :stream |
27+
stream nextPutAll: '```
28+
foo
29+
self
30+
````' ].
31+
]
32+
33+
{ #category : 'running' }
34+
MicCodeIndentationCheckerTest >> setUp [
35+
super setUp.
36+
37+
fileSystem := FileSystem memory.
38+
self generateFilesystemExample.
39+
checker := MicCodeIndentationChecker new.
40+
]
41+
42+
{ #category : 'tests' }
43+
MicCodeIndentationCheckerTest >> testIndentationCorrect [
44+
checker checkProject: fileSystem / 'indentationCorrect.md'.
45+
self assert: checker isOkay.
46+
]
47+
48+
{ #category : 'tests' }
49+
MicCodeIndentationCheckerTest >> testIndentationWrongDetected [
50+
checker checkProject: fileSystem / 'indentationWrong.md'.
51+
self deny: checker isOkay.
52+
self assert: checker results size equals: 1.
53+
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Class {
2+
#name : 'MicCodeIndentationResult',
3+
#superclass : 'MicAbstractResult',
4+
#instVars : [
5+
'detail'
6+
],
7+
#category : 'Microdown-Rules-CodeIndetation',
8+
#package : 'Microdown-Rules',
9+
#tag : 'CodeIndetation'
10+
}
11+
12+
{ #category : 'accessing' }
13+
MicCodeIndentationResult >> detail [
14+
15+
^ detail
16+
]
17+
18+
{ #category : 'accessing' }
19+
MicCodeIndentationResult >> detail: anObject [
20+
21+
detail := anObject
22+
]
23+
24+
{ #category : 'accessing' }
25+
MicCodeIndentationResult >> explanation [
26+
^ 'Text: "' , micElement body
27+
, '" in file' , fileReference fullName
28+
, ' contains a mistake: line ['
29+
, detail
30+
, '] should use tabs instead of spaces for indentation.'
31+
]

0 commit comments

Comments
 (0)