Skip to content

Commit

Permalink
First couple of Slime rules and tests converted to Reraku critiques
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrichau committed Jan 7, 2024
1 parent b6ee952 commit 1a385fc
Show file tree
Hide file tree
Showing 74 changed files with 680 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ baselinePharo: spec
requires: #('Grease-Pharo100-Core');
includes: #('Grease-Tests-Pharo-Core') ];
package: 'Grease-Pharo100-Core' with: [ spec requires: #('Grease-Core') ];
package: 'Grease-Pharo90-Slime' with: [ spec requires: #('Grease-Core') ];
package: 'Grease-Tests-Slime' with: [ spec requires: #('Grease-Pharo90-Slime') ].
package: 'Grease-Pharo110-Slime' with: [ spec requires: #('Grease-Core') ];
package: 'Grease-Tests-Pharo-Slime' with: [ spec requires: #('Grease-Pharo110-Slime') ].

spec
group: 'Slime' with: #('Grease-Pharo90-Slime');
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
self packageOrganizer ensurePackage: #BaselineOfGrease withTags: #('Manifest')!
SystemOrganization addCategory: #BaselineOfGrease!
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ version info
version
"Answer the Grease version"

^ (GRVersion major: 1 minor: 12 revision: 2)
^ (GRVersion major: 1 minor: 15 revision: 0)
yourself
5 changes: 5 additions & 0 deletions repository/Grease-Pharo110-Slime.package/.filetree
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"separateMethodMetaAndSource" : false,
"noMethodMetaData" : true,
"useCypressPropertiesFile" : true
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing - interest
checksClass

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

^ aClass isMeta not
and: [ (aClass includesSelector: #initialize)
and: [ (#(GRObject GRNotification GRNotification GRError RBLintRule RBTransformationRule) noneSatisfy: [ :each |
aClass includesBehavior: (Smalltalk globals at: each) ])
and: [ aClass class methodDictionary noneSatisfy: [ :each |
matcher
executeTree: each parseTree
initialAnswer: false ] ] ] ]
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,8 @@
initialization
initialize

super initialize.
matcher := RBParseTreeSearcher new.
matcher
matches: 'self basicNew initialize'
do: [ :node :answer | true ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
name

^ '#basicNew initialize is missing'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
rationale

^ '#initialize is not called implicitly when sending #new to an object in all Smalltalk dialects. Consider subclassing GRObject.'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"commentStamp" : "",
"super" : "GRReSlimeBlockLintRule",
"category" : "Grease-Pharo110-Slime",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"matcher"
],
"name" : "GRBasicNewInitializeMissingRule",
"type" : "normal"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
hooks
afterCheck: aNode mappings: mappingDict

| method |
method := aNode methodNode.
" This ensures that the description is of the form ClassName>>#selector:"
(aNode arguments first isLiteralNode
and: [ aNode arguments first value isString
and: [ method methodClass name greaseString , '>>#' , method selector greaseString ~= aNode arguments first value ] ]) ifTrue: [ ^ true ].

" This ensures that the description is a string and ends with a dot."
^ (aNode arguments size > 1
and: [ aNode arguments second isLiteralNode
and: [ aNode arguments second value isString
and: [ (aNode arguments second value endsWithSubCollection: '.') not ] ] ])
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
group

^ 'Grease Formatting'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
initialization
initialize

super initialize.
self
matchesAny: #(
'``@receiver greaseDeprecatedApi: ``@arg1'
'``@receiver greaseDeprecatedApi: ``@arg1 details: ``@arg2' )
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
name

^ 'Invalid use of deprecated API protocol.'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
rationale

^ 'Make sure to follow the following pattern: self greaseDeprecatedApi: ''Class>>#selector'' details: ''Some description''.'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "",
"super" : "GRReSlimeParseTreeLintRule",
"category" : "Grease-Pharo110-Slime",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "GRDeprecatedApiProtocolRule",
"type" : "normal"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "",
"super" : "ReAbstractRule",
"category" : "Grease-Pharo110-Slime",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "GRReSlimeBlockLintRule",
"type" : "normal"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "",
"super" : "ReNodeMatchRule",
"category" : "Grease-Pharo110-Slime",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "GRReSlimeParseTreeLintRule",
"type" : "normal"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SystemOrganization addCategory: #'Grease-Pharo110-Slime'!
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(name 'Grease-Pharo110-Slime')
1 change: 1 addition & 0 deletions repository/Grease-Pharo110-Slime.package/properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ }
5 changes: 5 additions & 0 deletions repository/Grease-Tests-Pharo-Slime.package/.filetree
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"separateMethodMetaAndSource" : false,
"noMethodMetaData" : true,
"useCypressPropertiesFile" : true
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
running-checks
assertRule: aRuleClass expectedMatches: aCollection

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

self run: aRuleClass ignoring: aCollectionOfIgnoredEntities do: [ :critiques | | critiquedEntities |
critiquedEntities := critiques collect:[ :critique | critique sourceAnchor entity ].
critiquedEntities do:[ :critiquedEntity |
self
assert: (aCollectionOfExpectedEntities includes: critiquedEntity)
description: critiquedEntity printString , ' should not be reported' ].
aCollectionOfExpectedEntities do: [ :expectedEntity |
self
assert: (critiquedEntities includes: expectedEntity)
description: expectedEntity printString , ' should be reported' ] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
accessing-code
canParse: aString
RBParser
parseMethod: aString
onError: [ :err :pos | ^ false ].
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
category
^ self class category , '-Data'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
accessing-code
compile: aString in: aClass

GRPlatform current
compile: aString
into: aClass
classified: #accessing
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing-code
defineClass: aClassSymbol superclass: aSuperSymbol
"For compatibility"
^ self defineSubClassOf: aSuperSymbol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
accessing-code
defineSubClassOf: aSuperSymbol

| class |
class := SystemVersion current major >= 12
ifTrue: [
factory make: [ :aBuilder |
aBuilder
superclass: (Smalltalk at: aSuperSymbol);
package: self category ] ]
ifFalse: [
factory
newSubclassOf: (Smalltalk at: aSuperSymbol)
instanceVariableNames: ''
classVariableNames: 'classVarsString'
category: self category ].
environment
addClass: class;
addClass: class classSide.
^ class
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
accessing
rules
^ OrderedCollection new
addAll: GRReSlimeBlockLintRule allSubclasses;
addAll: GRReSlimeParseTreeLintRule allSubclasses;
" addAll: GRSlimeTransformationRule allSubclasses;"
yourself
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
running-checks
run: aRuleClass ignoring: aCollectionOfEntities do: aBlock

| rules rule runner |
rules := self rules
collect: [ :each | each new ].
rule := rules
detect: [ :each | each isKindOf: aRuleClass ]
ifNone: [ self error: ('{1} is not a slime rule' format: { aRuleClass name }) ].
self
assert: (rule name isString and: [ rule name notEmpty ])
description: aRuleClass name , ' has no name'.
self
assert: (rule rationale isString and: [ rule rationale notEmpty and: [ rule rationale endsWithSubCollection: '.' ] ])
description: aRuleClass name , ' has no rationale'.
runner := ReSmalllintChecker new.
rules do: [ :each |
runner
rule: { each };
environment: environment;
run ].
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' ].
aBlock value: (runner criticsOf: rule).
^ rule
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
running
runCase
GRPlatform current doSilently: [ super runCase ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
running-checks
runTransformation: aClass changes: aCollection

| expected |
expected := aCollection
collect: [ :each | RBParser parseMethod: each ].
self run: aClass ignoring: Array new do: [ :rule :rules |
rule changes do: [ :change |
self
assert: (expected anySatisfy: [ :parseTree | change parseTree = parseTree ])
description: change selector , ' should not be transformed' ].
expected do: [ :parseTree |
self
assert: (rule changes anySatisfy: [ :change | change parseTree = parseTree ])
description: parseTree selector , ' should be transformed' ] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
running
setUp
super setUp.
factory := ClassFactoryForTestCase new.
model := RBNamespace new.
environment := RBClassEnvironment new
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
running
tearDown

super tearDown.
factory cleanUp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tests-transform
testAnsiBooleansRule
<expectedFailure>
| class |
class := self defineSubClassOf: #GRObject.
self compile: 'and 1 and: [ 2 ] and: [ 3 ] and: [ 4 ]' in: class.
self compile: 'or 1 or: [ 2 ] or: [ 3 ] or: [ 4 ]' in: class.
self
runTransformation: GRAnsiBooleansRule
changes: #(
'and 1 and: [ 2 and: [ 3 and: [ 4 ] ] ]'
'or 1 or: [ 2 or: [ 3 or: [ 4 ] ] ]' )
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests-transform
testAnsiCharacterRule
<expectedFailure>
| class |
class := self defineSubClassOf: #GRObject.
self compile: 'character Character value: 123' in: class.
self compile: 'characterRange $a to: $c' in: class.
self
runTransformation: GRAnsiCharactersRule
changes: #('character Character codePoint: 123' 'characterRange ''abc''')
Loading

0 comments on commit 1a385fc

Please sign in to comment.