File tree Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ Class {
2
+ #name : ' ReNilBranchRuleTest' ,
3
+ #superclass : ' ReAbstractRuleTestCase' ,
4
+ #category : ' General-Rules-Tests-Migrated' ,
5
+ #package : ' General-Rules-Tests' ,
6
+ #tag : ' Migrated'
7
+ }
8
+
9
+ { #category : ' tests' }
10
+ ReNilBranchRuleTest >> testRuleNotViolated [
11
+
12
+ | critiques |
13
+ self class
14
+ compile: ' method 1 < 0 ifTrue: [ 1 ]'
15
+ classified: ' test-helper' .
16
+ [
17
+ critiques := self myCritiquesOnMethod: self class >> #method .
18
+ self assertEmpty: critiques ] ensure : [
19
+ (self class >> #method ) removeFromSystem ]
20
+ ]
21
+
22
+ { #category : ' tests' }
23
+ ReNilBranchRuleTest >> testRuleWithIfFalse [
24
+
25
+ | critiques |
26
+ self class
27
+ compile: ' method 1 < 0 ifFalse: [ 1 ] ifTrue: [ nil ]'
28
+ classified: ' test-helper' .
29
+ [
30
+ critiques := self myCritiquesOnMethod: self class >> #method .
31
+ self assert: critiques size equals: 1 ] ensure : [
32
+ (self class >> #method ) removeFromSystem ]
33
+ ]
34
+
35
+ { #category : ' tests' }
36
+ ReNilBranchRuleTest >> testRuleWithIfTrue [
37
+
38
+ | critiques |
39
+ self class
40
+ compile: ' method 1 < 0 ifTrue: [ 1 ] ifFalse: [ nil ]'
41
+ classified: ' test-helper' .
42
+ [
43
+ critiques := self myCritiquesOnMethod: self class >> #method .
44
+ self assert: critiques size equals: 1 ] ensure : [
45
+ (self class >> #method ) removeFromSystem ]
46
+ ]
Original file line number Diff line number Diff line change
1
+ "
2
+ this smell arise when a branch nil useless is detected.
3
+ "
4
+ Class {
5
+ #name : ' ReNilBranchRule' ,
6
+ #superclass : ' ReNodeRewriteRule' ,
7
+ #category : ' General-Rules-Migrated' ,
8
+ #package : ' General-Rules' ,
9
+ #tag : ' Migrated'
10
+ }
11
+
12
+ { #category : ' accessing' }
13
+ ReNilBranchRule >> group [
14
+
15
+ ^ ' Design Flaws'
16
+ ]
17
+
18
+ { #category : ' initialization' }
19
+ ReNilBranchRule >> initialize [
20
+
21
+ super initialize
22
+ replace: ' `@condition ifTrue: [ `@.statements] ifFalse: [ nil ]'
23
+ with: ' `@condition ifTrue: [ `@.statements]' ;
24
+ replace: ' `@condition ifFalse: [ `@.statements] ifTrue: [ nil ]'
25
+ with: ' `@condition ifFalse: [ `@.statements]'
26
+ ]
27
+
28
+ { #category : ' accessing' }
29
+ ReNilBranchRule >> name [
30
+
31
+ ^ ' branch nil is useless'
32
+ ]
You can’t perform that action at this time.
0 commit comments