Skip to content

Commit

Permalink
add ReOverridingExtentsionMethod rule
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-krivanek committed Apr 29, 2024
1 parent 4ca1de3 commit 32b1dd6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/General-Rules/ReOverridingExtentsionMethod.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"
A rule that checks whether a method is an extension and whether it overrides an existing method. Such a method is usually a bug or wrongly classified.
"
Class {
#name : 'ReOverridingExtentsionMethod',
#superclass : 'ReAbstractRule',
#category : 'General-Rules-Migrated',
#package : 'General-Rules',
#tag : 'Migrated'
}

{ #category : 'running' }
ReOverridingExtentsionMethod >> basicCheck: aMethod [
^ aMethod isExtension and: [
| superMethod |
superMethod := aMethod origin superclass ifNotNil: [ :class |
class lookupSelector: aMethod selector ].
superMethod notNil and: [
"Ignore overrides of extension methods in special classes.
These may be name clashes or intended overrides of framework
methods."
(self specialClasses includes: superMethod methodClass) not and: [
"We allow extensions from the same package to override, so that
hierarchies can be extended with overriding functionality."
superMethod package ~= aMethod package ] ] ]
]

{ #category : 'accessing' }
ReOverridingExtentsionMethod >> group [
^ 'Potential Bugs'
]

{ #category : 'accessing' }
ReOverridingExtentsionMethod >> name [

^ 'An extension method overrides another method'
]

{ #category : 'private' }
ReOverridingExtentsionMethod >> specialClasses [
^ {ProtoObject. Object. Behavior. Class. ClassDescription}
]

0 comments on commit 32b1dd6

Please sign in to comment.