Skip to content

Commit

Permalink
Merge pull request #10140 from astares/10139-Provide-Autofix-for-RePr…
Browse files Browse the repository at this point in the history
…operMethodProtocolNameRule

Provide Autofix for ReProperMethodProtocolNameRule
  • Loading branch information
MarcusDenker committed Oct 13, 2021
2 parents d060dee + d79a016 commit 7338dd6
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 35 deletions.
Expand Up @@ -8,7 +8,7 @@ Class {
}

{ #category : #idioms }
ReProperMethodProtocolNameForAccessingRule >> protocolIdiom [
ReProperMethodProtocolNameForAccessingRule class >> protocolIdiom [

^self use: 'accessing' insteadOf: #('accessor' 'accessors' 'acessing' 'acccessing' 'accesing' 'acesing')
]
Expand Up @@ -8,7 +8,7 @@ Class {
}

{ #category : #idioms }
ReProperMethodProtocolNameForConvertingRule >> protocolIdiom [
ReProperMethodProtocolNameForConvertingRule class >> protocolIdiom [

^self use: 'converting' insteadOf: #('conversion' 'conversions')
]
Expand Up @@ -8,7 +8,7 @@ Class {
}

{ #category : #idioms }
ReProperMethodProtocolNameForInstanceCreationRule >> protocolIdiom [
ReProperMethodProtocolNameForInstanceCreationRule class >> protocolIdiom [

^self use: 'instance creation' insteadOf: #('instance-creation' 'instances-creation' 'instances creation')
]
14 changes: 7 additions & 7 deletions src/Renraku/ReProperMethodProtocolNameForTestsRule.class.st
Expand Up @@ -7,15 +7,15 @@ Class {
#category : #'Renraku-Rules'
}

{ #category : #idioms }
ReProperMethodProtocolNameForTestsRule class >> protocolIdiom [

^self use: 'tests' insteadOf: #('test')
]

{ #category : #running }
ReProperMethodProtocolNameForTestsRule >> basicCheck: aMethod [
"We only check for SUnit test methods"

^ aMethod isTestMethod and: [ self badMethodProtocolNames includes: aMethod category ]
]

{ #category : #idioms }
ReProperMethodProtocolNameForTestsRule >> protocolIdiom [

^self use: 'tests' insteadOf: #('test')
^ aMethod isTestMethod and: [ self class badMethodProtocolNames includes: aMethod category ]
]
Expand Up @@ -8,7 +8,7 @@ Class {
}

{ #category : #idioms }
ReProperMethodProtocolNameForUtilitiesRule >> protocolIdiom [
ReProperMethodProtocolNameForUtilitiesRule class >> protocolIdiom [

^self use: 'utilities' insteadOf: #('utils' 'utility')
]
75 changes: 51 additions & 24 deletions src/Renraku/ReProperMethodProtocolNameRule.class.st
Expand Up @@ -7,22 +7,45 @@ Subclasses should override #protocolIdiom to return an association of a good pro
Class {
#name : #ReProperMethodProtocolNameRule,
#superclass : #ReAbstractRule,
#instVars : [
'methodProtocolName'
],
#category : #'Renraku-Rules'
}

{ #category : #'private - accessing' }
ReProperMethodProtocolNameRule class >> badMethodProtocolNames [

^self protocolIdiom value collect: [:each | each asSymbol ]
]

{ #category : #'testing - interest' }
ReProperMethodProtocolNameRule class >> checksMethod [
"This one is abstract but subclasses should run as rules"

^ self name ~= #ReProperMethodProtocolNameRule
]

{ #category : #'private - accessing' }
ReProperMethodProtocolNameRule class >> goodMethodProtocolName [

^self protocolIdiom key
]

{ #category : #testing }
ReProperMethodProtocolNameRule class >> isAbstract [

^ self == ReProperMethodProtocolNameRule
]

{ #category : #idioms }
ReProperMethodProtocolNameRule class >> protocolIdiom [
"Subclasses should override to return an association between a
wished category and an array of category names that are not so good."

^self subclassResponsibility
]

{ #category : #'private - utilities' }
ReProperMethodProtocolNameRule class >> use: valid insteadOf: arrayOfInvalid [
"Instead of directly creating an array we use this utility method for better readability
Expand All @@ -31,21 +54,23 @@ ReProperMethodProtocolNameRule class >> use: valid insteadOf: arrayOfInvalid [
^valid -> arrayOfInvalid
]

{ #category : #'private - accessing' }
ReProperMethodProtocolNameRule >> badMethodProtocolNames [

^self protocolIdiom value collect: [:each | each asSymbol]
]

{ #category : #running }
ReProperMethodProtocolNameRule >> basicCheck: aMethod [
^ self badMethodProtocolNames includes: aMethod category
self methodProtocolName: aMethod category.
^ self class badMethodProtocolNames includes: aMethod category
]

{ #category : #'private - accessing' }
ReProperMethodProtocolNameRule >> goodMethodProtocolName [

^self protocolIdiom key printString
{ #category : #helpers }
ReProperMethodProtocolNameRule >> critiqueFor: aMethod [
| proposedCategory |
proposedCategory := self class goodMethodProtocolName asSymbol.

^ (ReRefactoringCritique
withAnchor: (self anchorFor: aMethod)
by: self) refactoring: (RBMethodProtocolTransformation
protocol: { proposedCategory }
inMethod: aMethod selector
inClass: aMethod methodClass name) asRefactoring
]

{ #category : #accessing }
Expand All @@ -55,28 +80,30 @@ ReProperMethodProtocolNameRule >> group [
]

{ #category : #accessing }
ReProperMethodProtocolNameRule >> name [
^ 'Method categorization: use ', self goodMethodProtocolName, ' as protocol name'
ReProperMethodProtocolNameRule >> methodProtocolName [

^ methodProtocolName
]

{ #category : #idioms }
ReProperMethodProtocolNameRule >> protocolIdiom [
"Subclasses should override to return an association between a
wished category and an array of category names that are not so good."

^self subclassResponsibility
{ #category : #accessing }
ReProperMethodProtocolNameRule >> methodProtocolName: anObject [

methodProtocolName := anObject
]

{ #category : #accessing }
ReProperMethodProtocolNameRule >> rationale [
^ 'Check if the method protocol name is appropriate and fulfils common expectations.'
ReProperMethodProtocolNameRule >> name [

^ 'Method categorization: use '''
, self class goodMethodProtocolName
, ''' as protocol name instead of '''
, self methodProtocolName asString , ''''
]

{ #category : #accessing }
ReProperMethodProtocolNameRule >> severity [
ReProperMethodProtocolNameRule >> rationale [

^ #information
^ 'Check if the method protocol name is appropriate and fulfils common expectations.'
]

{ #category : #'private - utilities' }
Expand Down

0 comments on commit 7338dd6

Please sign in to comment.