-
Notifications
You must be signed in to change notification settings - Fork 44
Feature/method structure #1009
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/method-structure
Mar 22, 2026
+158
−0
Merged
Feature/method structure #1009
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 3f9c6cb
Add method structure checker for empty line after selector without co…
Fanirindrainy c4970b1
Add class comment to MicMethodStructureChecker.
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,50 @@ | ||
| " | ||
| I check that methods in code blocks have an empty line after the selector when there is no comment. | ||
|
|
||
| Example of incorrect method (no comment, no empty line): | ||
| goodWordFor: aString | ||
| | pair | | ||
| pair := pairs detect: [ :each | each key = aString ]. | ||
| ^ pair value | ||
|
|
||
| Example of correct method (no comment, empty line after selector): | ||
| goodWordFor: aString | ||
|
|
||
| | pair | | ||
| pair := pairs detect: [ :each | each key = aString ]. | ||
| ^ pair value | ||
|
|
||
| Example of correct method (with comment, no empty line needed): | ||
| goodWordFor: aString | ||
| ""there is a comment"" | ||
| | pair | | ||
| pair := pairs detect: [ :each | each key = aString ]. | ||
| ^ pair value | ||
| " | ||
| Class { | ||
| #name : 'MicMethodStructureChecker', | ||
| #superclass : 'MicChecker', | ||
| #category : 'Microdown-Rules-MethodStructure', | ||
| #package : 'Microdown-Rules', | ||
| #tag : 'MethodStructure' | ||
| } | ||
|
|
||
| { #category : 'visiting' } | ||
| MicMethodStructureChecker >> visitCode: aMicCode [ | ||
| | lines firstLine secondLine | | ||
| lines := aMicCode body lines. | ||
| lines size < 2 ifTrue: [ ^ self ]. | ||
| firstLine := lines first. | ||
| secondLine := lines second. | ||
| "If the second line begins with a comment, that's correct." | ||
| (secondLine trimLeft beginsWith: '"') ifTrue: [ ^ self ]. | ||
| "If the second line is empty, it's correct." | ||
| secondLine trimLeft isEmpty ifTrue: [ ^ self ]. | ||
| "ifelse, theres's a blank line missing after the selector" | ||
| results add: (MicMethodStructureResult new | ||
| micElement: aMicCode; | ||
| inFile: aMicCode; | ||
| detail: firstLine; | ||
| yourself | ||
| ) | ||
| ] | ||
77 changes: 77 additions & 0 deletions
77
src/Microdown-Rules/MicMethodStructureCheckerTest.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,77 @@ | ||
| Class { | ||
| #name : 'MicMethodStructureCheckerTest', | ||
| #superclass : 'TestCase', | ||
| #instVars : [ | ||
| 'fileSystem', | ||
| 'checker' | ||
| ], | ||
| #category : 'Microdown-Rules-MethodStructure', | ||
| #package : 'Microdown-Rules', | ||
| #tag : 'MethodStructure' | ||
| } | ||
|
|
||
| { #category : 'running' } | ||
| MicMethodStructureCheckerTest >> generateFilesystemExample [ | ||
| | file | | ||
| file := fileSystem workingDirectory / 'methodWrong.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: '``` | ||
| goodWordFor: aString | ||
| | pair | | ||
| pair := pairs detect: [ :each | each key = aString ]. | ||
| ^ pair value | ||
|
|
||
| `````' | ||
| ]. | ||
| file := fileSystem workingDirectory / 'methodCorrect.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: '``` | ||
| goodWordFor: aString | ||
|
|
||
| | pair | | ||
| pair := pairs detect: [ :each | each key = aString ]. | ||
| ^ pair value | ||
|
|
||
| `````' | ||
| ]. | ||
| file := fileSystem workingDirectory / 'methodWithComment.md'. | ||
| file writeStreamDo: [ :stream | | ||
| stream nextPutAll: '``` | ||
| goodWordFor: aString | ||
| "there is a comment" | ||
| | pair | | ||
| pair := pairs detect: [ :each | each key = aString ]. | ||
| ^ pair value | ||
|
|
||
| `````' | ||
| ]. | ||
| ] | ||
|
|
||
| { #category : 'running' } | ||
| MicMethodStructureCheckerTest >> setUp [ | ||
| super setUp. | ||
|
|
||
| fileSystem := FileSystem memory. | ||
| self generateFilesystemExample. | ||
| checker := MicMethodStructureChecker new. | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| MicMethodStructureCheckerTest >> testMethodCorrect [ | ||
| checker checkProject: fileSystem / 'methodCorrect.md'. | ||
| self assert: checker isOkay. | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| MicMethodStructureCheckerTest >> testMethodWithCommentCorrect [ | ||
| checker checkProject: fileSystem / 'methodWithComment.md'. | ||
| self assert: checker isOkay. | ||
| ] | ||
|
|
||
| { #category : 'tests' } | ||
| MicMethodStructureCheckerTest >> testMethodWrongDetected [ | ||
| checker checkProject: fileSystem / 'methodWrong.md'. | ||
| self deny: checker isOkay. | ||
| self assert: checker results size equals: 1. | ||
| self assert: checker results first detail equals: 'goodWordFor: aString'. | ||
| ] |
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 : 'MicMethodStructureResult', | ||
| #superclass : 'MicAbstractResult', | ||
| #instVars : [ | ||
| 'detail' | ||
| ], | ||
| #category : 'Microdown-Rules-MethodStructure', | ||
| #package : 'Microdown-Rules', | ||
| #tag : 'MethodStructure' | ||
| } | ||
|
|
||
| { #category : 'accessing' } | ||
| MicMethodStructureResult >> detail [ | ||
|
|
||
| ^ detail | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| MicMethodStructureResult >> detail: aString [ | ||
|
|
||
| detail := aString | ||
| ] | ||
|
|
||
| { #category : 'accessing' } | ||
| MicMethodStructureResult >> explanation [ | ||
| ^ 'Text: "' , micElement body | ||
| , '" in file' , fileReference fullName | ||
| , ' contains a mistake: method [' | ||
| , detail | ||
| , '] should have an empty line after the selector when is no comment.' | ||
| ] |
Oops, something went wrong.
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.
Can you add a comment because I do tno really understand what it 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.
ok