Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelHely committed Jun 17, 2024
1 parent 4cc1ef8 commit ee96c9e
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
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 : 'tests' }
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 : 'tests' }
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 ]
]
45 changes: 45 additions & 0 deletions src/General-Rules/ReAssignmentFormattingRule.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"
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
]

0 comments on commit ee96c9e

Please sign in to comment.