diff --git a/src/General-Rules-Tests/ReAllAnyNoneSatisfyRuleTest.class.st b/src/General-Rules-Tests/ReAllAnyNoneSatisfyRuleTest.class.st new file mode 100644 index 00000000000..f6cab5808a6 --- /dev/null +++ b/src/General-Rules-Tests/ReAllAnyNoneSatisfyRuleTest.class.st @@ -0,0 +1,59 @@ +Class { + #name : 'ReAllAnyNoneSatisfyRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReAllAnyNoneSatisfyRuleTest >> testRuleNotViolated [ + + | critiques | + self class + compile: 'method + + ^ (OrderedCollection new) noneSatisfy: [ :each | each == 1 ]' + classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReAllAnyNoneSatisfyRuleTest >> testRuleWithAllSatisfy [ + + | critiques | + self class + compile: 'method + + (OrderedCollection new) do: [ :each | each == 1 ifFalse: [ ^ false ] ]. ^ true ' + classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReAllAnyNoneSatisfyRuleTest >> testRuleWithAnySatisfy [ + + | critiques | + self class + compile: 'method + + (OrderedCollection new) do: [ :each | each == 1 ifTrue: [ ^ true ] ]. ^ false ' + classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReAllAnyNoneSatisfyRuleTest >> testRuleWithNoneSatisfy [ + + | critiques | + self class + compile: 'method + + (OrderedCollection new) do: [ :each | each == 1 ifTrue: [ ^ false ] ]. ^ true ' + classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReBadMessageRuleTest.class.st b/src/General-Rules-Tests/ReBadMessageRuleTest.class.st new file mode 100644 index 00000000000..b403604dc24 --- /dev/null +++ b/src/General-Rules-Tests/ReBadMessageRuleTest.class.st @@ -0,0 +1,36 @@ +Class { + #name : 'ReBadMessageRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #instVars : [ + 'classFactory' + ], + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'running' } +ReBadMessageRuleTest >> setUp [ + super setUp. + classFactory := ClassFactoryForTestCase new. +] + +{ #category : 'running' } +ReBadMessageRuleTest >> tearDown [ + + classFactory cleanUp. + super tearDown +] + +{ #category : 'tests' } +ReBadMessageRuleTest >> testRule [ + + | critiques aClass| + aClass := classFactory make: [ :aBuilder | + aBuilder + tag: 'aTag'; + package: 'aPackage' ]. + aClass class compile: 'method 1 isMemberOf: Integer' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: aClass class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (aClass class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReCascadedNextPutAllsRuleTest.class.st b/src/General-Rules-Tests/ReCascadedNextPutAllsRuleTest.class.st new file mode 100644 index 00000000000..83d6c11fbda --- /dev/null +++ b/src/General-Rules-Tests/ReCascadedNextPutAllsRuleTest.class.st @@ -0,0 +1,25 @@ +Class { + #name : 'ReCascadedNextPutAllsRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReCascadedNextPutAllsRuleTest >> testRule [ + + | critiques | + self class compile: 'printOn: aStream aStream nextPutAll: ''test'', ''1'' ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #printOn:. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #printOn:) removeFromSystem ] +] + +{ #category : 'tests' } +ReCascadedNextPutAllsRuleTest >> testRuleNotViolated [ + + | critiques | + self class compile: 'printOn: aStream aStream nextPutAll: ''test''; nextPutAll: ''1'' ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #printOn:. + self assertEmpty: critiques ] ensure: [ (self class >> #printOn:) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReCollectionAtCollectionSizeRuleTest.class.st b/src/General-Rules-Tests/ReCollectionAtCollectionSizeRuleTest.class.st new file mode 100644 index 00000000000..8c5c856209a --- /dev/null +++ b/src/General-Rules-Tests/ReCollectionAtCollectionSizeRuleTest.class.st @@ -0,0 +1,31 @@ +Class { + #name : 'ReCollectionAtCollectionSizeRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReCollectionAtCollectionSizeRuleTest >> testRule [ + + | critiques | + self class + compile: + 'method | col | col := OrderedCollection. col add: 1; add: 2; add: 3. ^ col at: col size' + classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReCollectionAtCollectionSizeRuleTest >> testRuleNotViolated [ + + | critiques | + self class + compile: + 'method | col | col := OrderedCollection. col add: 1; add: 2; add: 3. ^ col last ' + classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReCollectionMessagesToExternalObjectRuleTest.class.st b/src/General-Rules-Tests/ReCollectionMessagesToExternalObjectRuleTest.class.st new file mode 100644 index 00000000000..2eb11cd4d38 --- /dev/null +++ b/src/General-Rules-Tests/ReCollectionMessagesToExternalObjectRuleTest.class.st @@ -0,0 +1,59 @@ +Class { + #name : 'ReCollectionMessagesToExternalObjectRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #instVars : [ + 'classFactory' + ], + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'running' } +ReCollectionMessagesToExternalObjectRuleTest >> setUp [ + super setUp. + classFactory := ClassFactoryForTestCase new +] + +{ #category : 'running' } +ReCollectionMessagesToExternalObjectRuleTest >> tearDown [ + + classFactory cleanUp. + super tearDown +] + +{ #category : 'tests' } +ReCollectionMessagesToExternalObjectRuleTest >> testRule [ + + | critiques aClass | + aClass := classFactory make: [ :aBuilder | + aBuilder + name: 'ClassToSupp' ; + slots: {#aCol }; + tag: 'aTag'; + package: 'aPackage' + ]. + aClass class compile: 'initialize super initialize. aCol := OrderedCollection new.' classified: 'initialization'. + aClass compile: 'aCol ^ aCol' classified: 'accessing'. + self class compile: 'method | aClass | aClass := ClassToSupp new. aClass aCol add: 1; add: 2' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 2 ] ensure: [ (self class >> #method) removeFromSystem ] + +] + +{ #category : 'tests' } +ReCollectionMessagesToExternalObjectRuleTest >> testRuleNotViolated [ + + | critiques aClass | + aClass := classFactory make: [ :aBuilder | + aBuilder + name: 'ClassForTest'; + slots: { #aCol }; + tag: 'aTag'; + package: 'aPackage' ]. + aClass class compile: 'adding aCol add: 1' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: aClass class >> #adding. + self assertEmpty: critiques ] ensure: [ aClass class >> #adding ] + + +] diff --git a/src/General-Rules-Tests/ReCollectionProtocolRuleTest.class.st b/src/General-Rules-Tests/ReCollectionProtocolRuleTest.class.st new file mode 100644 index 00000000000..c56344e9adf --- /dev/null +++ b/src/General-Rules-Tests/ReCollectionProtocolRuleTest.class.st @@ -0,0 +1,34 @@ +Class { + #name : 'ReCollectionProtocolRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReCollectionProtocolRuleTest >> testRule [ + + | critiques | + self class compile: 'method | set col | set := #(1 2 3). col := OrderedCollection new. set do: [ :number | col add: number ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReCollectionProtocolRuleTest >> testRuleNotViolatedWithCollect [ + + | critiques | + self class compile: 'method | set col | set := #(1 2 3). col := set collect: [ :number | number ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReCollectionProtocolRuleTest >> testRuleNotViolatedWithSelect [ + + | critiques | + self class compile: 'method | set col | set := #(1 2 3). col := set select: [ :number | number%2 ~= 0] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReDetectContainsRuleTest.class.st b/src/General-Rules-Tests/ReDetectContainsRuleTest.class.st new file mode 100644 index 00000000000..7347da19be8 --- /dev/null +++ b/src/General-Rules-Tests/ReDetectContainsRuleTest.class.st @@ -0,0 +1,43 @@ +Class { + #name : 'ReDetectContainsRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReDetectContainsRuleTest >> testRule1 [ + + | critiques | + self class compile: 'method | col | col := OrderedCollection new. col do: [ :elem | elem > 1 ifTrue: [ ^ elem ] ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReDetectContainsRuleTest >> testRule2 [ + + | critiques | + self class compile: 'method | col | col := OrderedCollection new. col do: [ :elem | elem > 1 ifFalse: [ ^ true ] ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReDetectContainsRuleTest >> testRuleNotViolatedWithContains [ + + | critiques | + self class compile: 'method | col | col := OrderedCollection new. col contains: 1 ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReDetectContainsRuleTest >> testRuleNotViolatedWithDetect [ + + | critiques | + self class compile: 'method | col | col := OrderedCollection new. col detect: [ :elem | elem > 1 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReDetectIfNoneRuleTest.class.st b/src/General-Rules-Tests/ReDetectIfNoneRuleTest.class.st new file mode 100644 index 00000000000..ce358f6e06f --- /dev/null +++ b/src/General-Rules-Tests/ReDetectIfNoneRuleTest.class.st @@ -0,0 +1,43 @@ +Class { + #name : 'ReDetectIfNoneRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReDetectIfNoneRuleTest >> testRuleNotViolated [ + + | critiques | + self class + compile: + 'method | temp | temp := OrderedCollection new. temp anySatisfy: [ :each | each > 1 ]' + classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReDetectIfNoneRuleTest >> testRuleWithContains [ + + | critiques | + self class + compile: + 'method | temp | temp := OrderedCollection new. temp contains: [ :each | each > 1 ] ' + classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReDetectIfNoneRuleTest >> testRuleWithDetect [ + + | critiques | + self class + compile: + 'method | temp | temp := OrderedCollection new. (temp detect: [ :each | each > 1 ] ifNone: [ nil ] ) isNil' + classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReEqualNilRuleTest.class.st b/src/General-Rules-Tests/ReEqualNilRuleTest.class.st new file mode 100644 index 00000000000..07c5cce575b --- /dev/null +++ b/src/General-Rules-Tests/ReEqualNilRuleTest.class.st @@ -0,0 +1,25 @@ +Class { + #name : 'ReEqualNilRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReEqualNilRuleTest >> testRule [ + + | critiques | + self class compile: 'method | arg | ^ arg = nil' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReEqualNilRuleTest >> testRuleNotViolated [ + + | critiques | + self class compile: 'method | arg | ^ arg isNil' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReGuardClauseRuleTest.class.st b/src/General-Rules-Tests/ReGuardClauseRuleTest.class.st new file mode 100644 index 00000000000..a624e48547f --- /dev/null +++ b/src/General-Rules-Tests/ReGuardClauseRuleTest.class.st @@ -0,0 +1,25 @@ +Class { + #name : 'ReGuardClauseRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReGuardClauseRuleTest >> testRule [ + + | critiques | + self class compile: 'method | arg | arg := 1. arg > 2 ifTrue: [ 1. 1. ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReGuardClauseRuleTest >> testRuleNotViolated [ + + | critiques | + self class compile: 'method | arg | arg := 1. arg > 2 ifFalse: [ ^ self ]. 1. 1. ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReIfNotNilDoRuleTest.class.st b/src/General-Rules-Tests/ReIfNotNilDoRuleTest.class.st new file mode 100644 index 00000000000..2678aa4d184 --- /dev/null +++ b/src/General-Rules-Tests/ReIfNotNilDoRuleTest.class.st @@ -0,0 +1,25 @@ +Class { + #name : 'ReIfNotNilDoRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReIfNotNilDoRuleTest >> testRule [ + + | critiques | + self class compile: 'method | arg | arg ifNotNilDo: [ arg := 1 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReIfNotNilDoRuleTest >> testRuleNotViolated [ + + | critiques | + self class compile: 'method | arg | arg ifNotNil: [ arg := 1 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReIsNilAndConditionalRuleTest.class.st b/src/General-Rules-Tests/ReIsNilAndConditionalRuleTest.class.st new file mode 100644 index 00000000000..808e0a79e98 --- /dev/null +++ b/src/General-Rules-Tests/ReIsNilAndConditionalRuleTest.class.st @@ -0,0 +1,61 @@ +Class { + #name : 'ReIsNilAndConditionalRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReIsNilAndConditionalRuleTest >> testRuleNotViolatedWithIfNil [ + + | critiques | + self class compile: 'method | arg | ^ arg isNil ifNil: [ arg := 1 ]' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReIsNilAndConditionalRuleTest >> testRuleNotViolatedWithIfNilIfNotNil [ + + | critiques | + self class compile: 'method | arg | ^ arg isNil ifNil: [ arg := 1 ] ifNotNil: [ arg := 2 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReIsNilAndConditionalRuleTest >> testRuleNotViolatedWithIfNotNil [ + + | critiques | + self class compile: 'method | arg | ^ arg isNil ifNotNil: [ arg := 2 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReIsNilAndConditionalRuleTest >> testRuleWithIsNilIfFalse [ + + | critiques | + self class compile: 'method | arg | ^ arg isNil ifFalse: [ arg := 1 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReIsNilAndConditionalRuleTest >> testRuleWithIsNilIfTrue [ + + | critiques | + self class compile: 'method | arg | ^ arg isNil ifTrue: [ arg := 1 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReIsNilAndConditionalRuleTest >> testRuleWithIsNilIfTrueIfFalse [ + + | critiques | + self class compile: 'method | arg | ^ arg isNil ifTrue: [ arg := 1 ] ifFalse: [ arg := 2 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReIsNotNilAndConditionalRuleTest.class.st b/src/General-Rules-Tests/ReIsNotNilAndConditionalRuleTest.class.st new file mode 100644 index 00000000000..4ab8ca686fd --- /dev/null +++ b/src/General-Rules-Tests/ReIsNotNilAndConditionalRuleTest.class.st @@ -0,0 +1,70 @@ +Class { + #name : 'ReIsNotNilAndConditionalRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReIsNotNilAndConditionalRuleTest >> testRuleNotViolatedIfNil [ + + | critiques | + self class compile: 'method | arg | ^ arg ifNil: [ arg := 1 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReIsNotNilAndConditionalRuleTest >> testRuleNotViolatedIfNotNil [ + + | critiques | + self class compile: 'method | arg | ^ arg ifNotNil: [ arg := 1 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReIsNotNilAndConditionalRuleTest >> testRuleNotViolatedIfNotNilIfNil [ + + | critiques | + self class compile: 'method | arg | ^ arg ifNotNil: [ arg := 2 ] ifNil: [ arg := 1 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReIsNotNilAndConditionalRuleTest >> testRuleWithIsNotNilIfFalse [ + + | critiques | + self class compile: 'method | arg | ^ arg isNotNil ifFalse: [ arg := 1 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReIsNotNilAndConditionalRuleTest >> testRuleWithIsNotNilIfTrueIfFalse [ + + | critiques | + self class compile: 'method | arg | ^ arg isNotNil ifTrue: [ arg := 1 ] ifFalse: [ arg := 2 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReIsNotNilAndConditionalRuleTest >> testRuleWithNotNilIfTrue [ + + | critiques | + self class compile: 'method | arg | ^ arg notNil ifTrue: [ arg := 1 ]' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReIsNotNilAndConditionalRuleTest >> testRuleWithNotNilIfTrueIfFalse [ + + | critiques | + self class compile: 'method | arg | ^ arg notNil ifTrue: [ arg := 1 ] ifFalse: [ arg := 2 ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReLiteralArrayContainsCommaRuleTest.class.st b/src/General-Rules-Tests/ReLiteralArrayContainsCommaRuleTest.class.st new file mode 100644 index 00000000000..66e13070d55 --- /dev/null +++ b/src/General-Rules-Tests/ReLiteralArrayContainsCommaRuleTest.class.st @@ -0,0 +1,25 @@ +Class { + #name : 'ReLiteralArrayContainsCommaRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReLiteralArrayContainsCommaRuleTest >> testRule [ + + | critiques | + self class compile: 'method #(#ok #o,k #t,t,t,t)' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReLiteralArrayContainsCommaRuleTest >> testRuleNotViolated [ + + | critiques | + self class compile: 'method #(#ok #R2D2 #t_t_t)' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReMinMaxRuleTest.class.st b/src/General-Rules-Tests/ReMinMaxRuleTest.class.st new file mode 100644 index 00000000000..1abdbe65a99 --- /dev/null +++ b/src/General-Rules-Tests/ReMinMaxRuleTest.class.st @@ -0,0 +1,46 @@ +Class { + #name : 'ReMinMaxRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #instVars : [ + 'classFactory' + ], + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReMinMaxRuleTest >> testRuleCase1 [ + + | critiques | + self class compile: 'method 1 < 2 ifTrue: [ 1 ] ifFalse: [ 2 ] ' classified: 'test-helper' . + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReMinMaxRuleTest >> testRuleCase2 [ + + | critiques | + self class compile: 'method 1 > 2 ifTrue: [ 1 ] ifFalse: [ 2 ] ' classified: 'test-helper' . + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReMinMaxRuleTest >> testRuleNotViolatedWithMax [ + + | critiques | + self class compile: 'method 1 max: b ' classified: 'test-helper' . + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReMinMaxRuleTest >> testRuleNotViolatedWithMin [ + + | critiques | + self class compile: 'method 1 min: b ' classified: 'test-helper' . + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReNoClassCommentRuleTest.class.st b/src/General-Rules-Tests/ReNoClassCommentRuleTest.class.st new file mode 100644 index 00000000000..2c5b859ba6b --- /dev/null +++ b/src/General-Rules-Tests/ReNoClassCommentRuleTest.class.st @@ -0,0 +1,49 @@ +Class { + #name : 'ReNoClassCommentRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #instVars : [ + 'classFactory' + ], + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'running' } +ReNoClassCommentRuleTest >> setUp [ + + super setUp. + classFactory := ClassFactoryForTestCase new +] + +{ #category : 'running' } +ReNoClassCommentRuleTest >> tearDown [ + + classFactory cleanUp. + super tearDown +] + +{ #category : 'tests' } +ReNoClassCommentRuleTest >> testRule [ + + | critiques classWithoutComment| + classWithoutComment := classFactory make: [ :builder | + builder + tag: 'aTag'; + package: 'aPackage' ]. + critiques := self myCritiquesOnClass: classWithoutComment. + self assert: critiques size equals: 1. +] + +{ #category : 'tests' } +ReNoClassCommentRuleTest >> testRuleNotViolated [ + + | critiques classWithoutComment| + classWithoutComment := classFactory make: [ :builder | + builder + tag: 'aTag'; + package: 'aPackage' ]. + classWithoutComment comment: 'Hello I am a comment'. + critiques := self myCritiquesOnClass: classWithoutComment. + self assertEmpty: critiques. +] diff --git a/src/General-Rules-Tests/ReNoSpaceAroundProtocolRuleTest.class.st b/src/General-Rules-Tests/ReNoSpaceAroundProtocolRuleTest.class.st new file mode 100644 index 00000000000..880227772c9 --- /dev/null +++ b/src/General-Rules-Tests/ReNoSpaceAroundProtocolRuleTest.class.st @@ -0,0 +1,25 @@ +Class { + #name : 'ReNoSpaceAroundProtocolRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReNoSpaceAroundProtocolRuleTest >> testRule [ + + | critiques | + self class compile: 'method ^1' classified: 'test-helper '. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReNoSpaceAroundProtocolRuleTest >> testRuleNotViolated [ + + | critiques | + self class compile: 'method ^1' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReShouldntRaiseErrorRuleTest.class.st b/src/General-Rules-Tests/ReShouldntRaiseErrorRuleTest.class.st new file mode 100644 index 00000000000..ce8b1057083 --- /dev/null +++ b/src/General-Rules-Tests/ReShouldntRaiseErrorRuleTest.class.st @@ -0,0 +1,16 @@ +Class { + #name : 'ReShouldntRaiseErrorRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReShouldntRaiseErrorRuleTest >> testRule [ + + | critiques | + self class compile: 'method self shouldnt: [ 1. ] raise: Error' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReSmalltalkGlobalsRuleTest.class.st b/src/General-Rules-Tests/ReSmalltalkGlobalsRuleTest.class.st new file mode 100644 index 00000000000..4522a93e159 --- /dev/null +++ b/src/General-Rules-Tests/ReSmalltalkGlobalsRuleTest.class.st @@ -0,0 +1,34 @@ +Class { + #name : 'ReSmalltalkGlobalsRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReSmalltalkGlobalsRuleTest >> testRule1 [ + + | critiques | + self class compile: 'method Smalltalk allClasses' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReSmalltalkGlobalsRuleTest >> testRule2 [ + + | critiques | + self class compile: 'method Smalltalk allClassesDo: [ 1. ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReSmalltalkGlobalsRuleTest >> testRuleNotViolated [ + + | critiques | + self class compile: 'method Smalltalk globals allClassesDo: [ 1. ] ' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReThemeAPIUpdateRuleTest.class.st b/src/General-Rules-Tests/ReThemeAPIUpdateRuleTest.class.st new file mode 100644 index 00000000000..b4976558eb1 --- /dev/null +++ b/src/General-Rules-Tests/ReThemeAPIUpdateRuleTest.class.st @@ -0,0 +1,25 @@ +Class { + #name : 'ReThemeAPIUpdateRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReThemeAPIUpdateRuleTest >> testRule [ + + | critiques | + self class compile: 'method UITheme current' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReThemeAPIUpdateRuleTest >> testRuleNotViolated [ + + | critiques | + self class compile: 'method Smalltalk ui theme' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReToDoCollectRuleTest.class.st b/src/General-Rules-Tests/ReToDoCollectRuleTest.class.st new file mode 100644 index 00000000000..4dea30dbb24 --- /dev/null +++ b/src/General-Rules-Tests/ReToDoCollectRuleTest.class.st @@ -0,0 +1,27 @@ +Class { + #name : 'ReToDoCollectRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReToDoCollectRuleTest >> testRule [ + + | critiques | + + self class compile: 'method | aCol | aCol := Array new: 10. 1 to: aCol size do: [ :i | aCol at: i put: 1 ]' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReToDoCollectRuleTest >> testRuleNotViolated [ + + | critiques | + + self class compile: 'method | aCol | aCol := Array new: 10. aCol collect: [ :i | ]' classified: 'test-helper'. + [ critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReToDoWithIncrementRuleTest.class.st b/src/General-Rules-Tests/ReToDoWithIncrementRuleTest.class.st new file mode 100644 index 00000000000..29aeaa3604f --- /dev/null +++ b/src/General-Rules-Tests/ReToDoWithIncrementRuleTest.class.st @@ -0,0 +1,59 @@ +Class { + #name : 'ReToDoWithIncrementRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReToDoWithIncrementRuleTest >> testRule [ + + | critiques | + self class + compile: + 'method 1 to: 100 do: [ :e | | counter | counter:= 1 .counter := counter + 1 ] ' + classified: 'test-helper'. + [ + critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReToDoWithIncrementRuleTest >> testRuleNotViolated [ + + | critiques | + self class + compile: + 'method | counter | counter := 1. 1 to: 100 do: [ counter := counter + 1 ] ' + classified: 'test-helper'. + [ + critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReToDoWithIncrementRuleTest >> testRuleNotViolatedWithBy [ + + | critiques | + self class + compile: + 'method | counter | counter := 1. 1 to: 100 by: 3 do: [ counter := counter + 1 ] ' + classified: 'test-helper'. + [ + critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ (self class >> #method) removeFromSystem ] +] + +{ #category : 'tests' } +ReToDoWithIncrementRuleTest >> testRuleWithBy [ + + | critiques | + self class + compile: + 'method 1 to: 100 by: 3 do: [ :e | | counter | counter:= 1 .counter := counter + 3 ] ' + classified: 'test-helper'. + [ + critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ (self class >> #method) removeFromSystem ] +] diff --git a/src/General-Rules-Tests/ReWhileTrueRuleTest.class.st b/src/General-Rules-Tests/ReWhileTrueRuleTest.class.st new file mode 100644 index 00000000000..a204bc43fac --- /dev/null +++ b/src/General-Rules-Tests/ReWhileTrueRuleTest.class.st @@ -0,0 +1,42 @@ +Class { + #name : 'ReWhileTrueRuleTest', + #superclass : 'ReAbstractRuleTestCase', + #category : 'General-Rules-Tests-Coding Idiom Violation', + #package : 'General-Rules-Tests', + #tag : 'Coding Idiom Violation' +} + +{ #category : 'tests' } +ReWhileTrueRuleTest >> testRule [ + + | critiques | + self class + compile: 'method | index stop | + stop := 5. + index := 1. + [ index <= stop ] + whileTrue: [ + index := index + 1 ]' + classified: 'test-helper'. + [ + critiques := self myCritiquesOnMethod: self class >> #method. + self assert: critiques size equals: 1 ] ensure: [ + (self class >> #method) removeFromSystem] +] + +{ #category : 'tests' } +ReWhileTrueRuleTest >> testRuleNotViolated [ + + | critiques | + self class + compile: 'method | index stop | + stop := 5. + index := 1. + index to: stop do: [ + index := index + 1 ]' + classified: 'test-helper'. + [ + critiques := self myCritiquesOnMethod: self class >> #method. + self assertEmpty: critiques ] ensure: [ + (self class >> #method) removeFromSystem] +] diff --git a/src/General-Rules/ReIsNotNilAndConditionalRule.class.st b/src/General-Rules/ReIsNotNilAndConditionalRule.class.st index 512346b1639..f44538999ee 100644 --- a/src/General-Rules/ReIsNotNilAndConditionalRule.class.st +++ b/src/General-Rules/ReIsNotNilAndConditionalRule.class.st @@ -1,5 +1,5 @@ " -Replaces isNotNil ifTrue , isNotNil ifFalse and isNotNil ifTrue:ifFalse by ifNotNil: , ifNil and ifNotNil:ifNil: to make the code more readable. Helps to avoid unnecesary temporal variables. +Replaces isNotNil ifTrue , isNotNil ifFalse and isNotNil ifTrue:ifFalse by ifNotNil: , ifNil: and ifNotNil:ifNil: to make the code more readable. Helps to avoid unnecesary temporal variables. Works also with notNil. " Class {