-
Notifications
You must be signed in to change notification settings - Fork 44
Feature/code indentation #1007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Ducasse
merged 4 commits into
pillar-markup:dev
from
Fanirindrainy:feature/code-indentation
Mar 22, 2026
Merged
Feature/code indentation #1007
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e15492
first commit after cloning
Fanirindrainy 2134a3b
Revert "first commit after cloning "
Fanirindrainy f8a30f5
Add code indentation checker for tabs vs spaces in code blocks
Fanirindrainy f1e718e
Fix CodeIndentation checker: remove unnecessary nextPul exception
Fanirindrainy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | ||
| } | ||
|
|
||
| { #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
53
src/Microdown-Rules/MicCodeIndentationCheckerTest.class.st
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.' | ||
| ] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.