Skip to content
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

add ReAssignmentFormattingRule and his tests #16846

Open
wants to merge 1 commit into
base: Pharo13
Choose a base branch
from
Open
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
47 changes: 47 additions & 0 deletions src/General-Rules-Tests/ReAssignmentFormattingRuleTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Class {
#name : 'ReAssignmentFormattingRuleTest',
#superclass : 'ReAbstractRuleTestCase',
#category : 'General-Rules-Tests-Formatting',
#package : 'General-Rules-Tests',
#tag : 'Formatting'
}

{ #category : 'running' }
ReAssignmentFormattingRuleTest >> testRuleCase1 [

| critiques |

self class compile: 'method | arg | arg:=1' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'running' }
ReAssignmentFormattingRuleTest >> testRuleCase2 [

| critiques |

self class compile: 'method | arg | arg:= 1' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReAssignmentFormattingRuleTest >> testRuleCase3 [

| critiques |

self class compile: 'method | arg | arg :=1' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ]
]

{ #category : 'tests' }
ReAssignmentFormattingRuleTest >> testRuleNotViolated [

| critiques |

self class compile: 'method | arg | arg := 1' classified: 'test-helper'.
[ critiques := self myCritiquesOnMethod: self class >> #method.
self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ]
]
44 changes: 44 additions & 0 deletions src/General-Rules/ReAssignmentFormattingRule.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"
This rule verify if there is spaces when you make an assignement

Prefer
arg := 1
over
arg:=1
"
Class {
#name : 'ReAssignmentFormattingRule',
#superclass : 'ReNodeBasedRule',
#category : 'General-Rules-Formatting',
#package : 'General-Rules',
#tag : 'Formatting'
}

{ #category : 'accessing' }
ReAssignmentFormattingRule class >> group [

^ 'Formatting'
]

{ #category : 'accessing' }
ReAssignmentFormattingRule class >> rationale [

^ 'there should be an space between the temporary, ":=" and the assignment variable'
]

{ #category : 'accessing' }
ReAssignmentFormattingRule class >> ruleName [

^ 'Assignment formatting'
]

{ #category : 'running' }
ReAssignmentFormattingRule >> basicCheck: aNode [

| arg variable |

aNode isAssignment ifFalse: [ ^ false ].
arg := aNode children first.
variable := aNode children second.
^ variable stop + 5 > arg start
]