-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Rinzwind/rein-in-last-period-rule
Add ReNoPeriodAfterReturnRule and remove ReUnnecessaryLastPeriodRule
- Loading branch information
Showing
4 changed files
with
94 additions
and
84 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
PharoWithStyle-Tests/ReNoPeriodAfterReturnRuleTest.class.st
This file contains 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,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
44
PharoWithStyle-Tests/ReUnnecessaryLastPeriodRuleTest.class.st
This file was deleted.
Oops, something went wrong.
This file contains 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,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 | ||
] |
This file was deleted.
Oops, something went wrong.