Skip to content

Commit

Permalink
ported rules: invalid object initialization and non-portable messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrichau committed Jan 7, 2024
1 parent d6705ff commit 81bec5c
Show file tree
Hide file tree
Showing 26 changed files with 105 additions and 30 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing - interest
checksMethod

^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
running
basicCheck: aMethod

^ (aMethod methodClass isMeta not
and: [ (aMethod selector beginsWithSubCollection: #initialize)
and: [ aMethod selector numArgs > 0
and: [ aMethod methodClass ~= GRObject
and: [ (aMethod methodClass includesBehavior: GRObject)
and: [ (aMethod superMessages includes: aMethod selector) not
and: [ aMethod selfMessages noneSatisfy: [ :each | each beginsWithSubCollection: #initialize ] ] ] ] ] ] ])
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
group

^ 'Grease Portability'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
name

^ 'Invalid object initialization'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
rationale

^ 'Initialize methods are required to call the designated initializer or its super implementation.'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "",
"super" : "GRReSlimeBlockLintRule",
"category" : "Grease-Pharo110-Slime",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "GRInvalidObjectInitializationRule",
"type" : "normal"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing - interest
checksNode

^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
running
basicCheck: anEntity

^ anEntity isMessage and:[ self methodNames includes: anEntity selector ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
group

^ 'Grease Portability'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
private
methodNames

^ #( anyOne withIndexCollect: )
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
name

^ 'Uses non portable message'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
rationale

^ 'Some methods are not portable accross different Smalltalk dialects.'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "",
"super" : "GRReSlimeBlockLintRule",
"category" : "Grease-Pharo110-Slime",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "GRNonPortableMessageRule",
"type" : "normal"
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
running-checks
assertRule: aRuleClass matches: expectedMatches

self assertRule: aRuleClass matches: expectedMatches ignoring: Array new
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
running-checks
assertRule: aRuleClass matches: expectedMatches ignoring: ignoredRuleClasses

self run: aRuleClass ignoring: ignoredRuleClasses do: [ :critiques | | critiquedEntities |
critiquedEntities := critiques collect:[ :critique | critique sourceAnchor entity ].
critiquedEntities do:[ :critiquedEntity |
self
assert: (expectedMatches includes: critiquedEntity)
description: ('{1} should not be reported' format: { critiquedEntity printString }) ].
expectedMatches do: [ :expectedEntity |
self
assert: (critiquedEntities includes: expectedEntity)
description: ('{1} should be reported' format: { expectedEntity printString }) ] ]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ rules
addAll: GRReSlimeBlockLintRule allSubclasses;
addAll: GRReSlimeParseTreeLintRule allSubclasses;
" addAll: GRSlimeTransformationRule allSubclasses;"
add: ReMultiplePeriodsTerminatingStatementRule;
yourself
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
running-checks
run: aRuleClass ignoring: aCollectionOfEntities do: aBlock
run: aRuleClass ignoring: ignoredRuleClasses do: aBlock

| rules rule runner |
rules := self rules
Expand All @@ -22,7 +22,7 @@ run: aRuleClass ignoring: aCollectionOfEntities do: aBlock
rules do: [ :each | | result |
result := runner criticsOf: each.
self
assert: (rule = each or: [ result isEmpty "and: [ each changes isEmpty ]) or: [ aCollectionOfEntities includes: each class ]" ])
description: each name , ' should not report errors' ].
assert: (rule = each or: [ result isEmpty or: [ ignoredRuleClasses includes: each class ] ])
description: ('{1} should not report errors' format: { each name }) ].
aBlock value: (runner criticsOf: rule).
^ rule
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ testBasicNewInitializeMissing
self compile: 'initialize' in: class.
self
assertRule: GRBasicNewInitializeMissingRule
expectedMatches: { class }
matches: { class }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ testDeprecatedApiProtocol
self compile: 'deprecated3 self greaseDeprecatedApi: ''GRSlimeMock>>#deprecated3'' details: ''Something.''' in: class.
self
assertRule: GRDeprecatedApiProtocolRule
expectedMatches: { class>>#deprecated2 . class>>#deprecated3 }
matches: { class>>#deprecated2 . class>>#deprecated3 }
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
tests-block
testEmptyStatements
"We added this test to make sure that this Pharo-supplied rule works because we previously had this one in Grease and it is important."
<expectedFailure>

| class |
class := self defineSubClassOf: #GRObject.
self compile: 'emptyStatement1. self and' in: class.
self compile: 'emptyStatement2 self and..' in: class.
self compile: 'emptyStatement3 self and."foo".' in: class.
self compile: 'emptyStatement4 self and."foo".self and' in: class.
self
runRule: GREmptyStatementsRule
selectors: #(emptyStatement1 emptyStatement2 emptyStatement3 emptyStatement4)
assertRule: ReMultiplePeriodsTerminatingStatementRule
matches: { class>>#emptyStatement1 . class>>#emptyStatement2 . class>>#emptyStatement3 . class>>#emptyStatement4 }
ignoring: (Array with: GRUnnecessaryLastPeriodRule)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests-block
testInvalidObjectInitialization
<expectedFailure>

| class |
class := self defineSubClassOf: #GRObject.
self compile: 'initializeFoo: aNumber' in: class.
self
runRule: GRInvalidObjectInitializationRule
selectors: #(initializeFoo:)
assertRule: GRInvalidObjectInitializationRule
matches: { class>>#initializeFoo: }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests-block
testNonPortableMessageRule
<expectedFailure>

| class |
class := self defineSubClassOf: #GRObject.

Expand All @@ -11,5 +11,5 @@ testNonPortableMessageRule
self compile: 'valid2 ^ Array new do: [ :each | each hash ]' in: class.

self
runRule: GRNonPortableMessageRule
selectors: #(invalid1 invalid2)
assertRule: GRNonPortableMessageRule
matches: { class>>#invalid1 . class>>#invalid2 }

0 comments on commit 81bec5c

Please sign in to comment.