Skip to content

Commit

Permalink
Merge pull request #1 from Rinzwind/rein-in-last-period-rule
Browse files Browse the repository at this point in the history
Add ReNoPeriodAfterReturnRule and remove ReUnnecessaryLastPeriodRule
  • Loading branch information
Johan Brichau authored Apr 19, 2024
2 parents 4e6dcdd + aa85adb commit daa93b0
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 84 deletions.
48 changes: 48 additions & 0 deletions PharoWithStyle-Tests/ReNoPeriodAfterReturnRuleTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Class {
#name : #ReNoPeriodAfterReturnRuleTest,
#superclass : #ReAbstractRuleTestCase,
#category : #'PharoWithStyle-Tests'
}

{ #category : #examples }
ReNoPeriodAfterReturnRuleTest >> lastPeriods [

#(true false) atRandom ifTrue: [
self crTrace: '1'.
self crTrace: '2'. ].
self crTrace: '3'.
self crTrace: '4'.
]

{ #category : #helpers }
ReNoPeriodAfterReturnRuleTest >> myCritiquesOnNodesInMethod: aMethod [

| critiques |

critiques := OrderedCollection new.
aMethod ast nodesDo: [ :node |
self subjectUnderTest new
check: node forCritiquesDo:[ :critique | critiques add: critique ] ].
^ critiques
]

{ #category : #violations }
ReNoPeriodAfterReturnRuleTest >> periodAfterReturn [

#(true false) atRandom ifTrue: [
self crTrace: '1'.
^ self crTrace: '2'. ].
self crTrace: '3'.
^ self crTrace: '4'.
]

{ #category : #tests }
ReNoPeriodAfterReturnRuleTest >> testRule [

| critiques |

critiques := self myCritiquesOnNodesInMethod: self class >> #periodAfterReturn.
self assert: critiques size equals: 2.
critiques := self myCritiquesOnNodesInMethod: self class >> #lastPeriods.
self assert: critiques size equals: 0
]
44 changes: 0 additions & 44 deletions PharoWithStyle-Tests/ReUnnecessaryLastPeriodRuleTest.class.st

This file was deleted.

46 changes: 46 additions & 0 deletions PharoWithStyle/ReNoPeriodAfterReturnRule.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Class {
#name : #ReNoPeriodAfterReturnRule,
#superclass : #ReNodeBasedRule,
#category : #PharoWithStyle
}

{ #category : #helpers }
ReNoPeriodAfterReturnRule >> anchorFor: aNode [

^ ReIntervalSourceAnchor
entity: aNode
interval: (Interval from: aNode parent periods last to: aNode parent periods last + 1)
]

{ #category : #running }
ReNoPeriodAfterReturnRule >> basicCheck: node [

^ node isReturn and: [
node == node parent statements last and: [
node parent periods notEmpty and: [
node parent periods last > node stop ] ] ]
]

{ #category : #accessing }
ReNoPeriodAfterReturnRule >> group [

^ 'Formatting'
]

{ #category : #accessing }
ReNoPeriodAfterReturnRule >> name [

^ 'Return statements should not end with a period'
]

{ #category : #accessing }
ReNoPeriodAfterReturnRule >> rationale [

^ 'Return statements are conventionally not ended with a period as they cannot be followed by another statement.'
]

{ #category : #accessing }
ReNoPeriodAfterReturnRule >> severity [

^ #information
]
40 changes: 0 additions & 40 deletions PharoWithStyle/ReUnnecessaryLastPeriodRule.class.st

This file was deleted.

0 comments on commit daa93b0

Please sign in to comment.