pharo-project / pharo

Pharo is a dynamic reflective pure object-oriented language supporting live programming inspired by Smalltalk.
http://pharo.org
Other
1.21k stars 355 forks source link

New rule idea: Method returning in conditional but still having statements #6326

Open jecisc opened 4 years ago

jecisc commented 4 years ago

In Pharo, by default it is not possible to write statements after a return. But it is possible to write statements after a condition that return.

I propose a rule to find cases such as:

self toto ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ].
self tata

or

self toto ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]; tata

The conditions to match would be that the method has a AST node matching:

jecisc commented 4 years ago

The way to query for this is mostly done here:

https://github.com/jecisc/Chanel/pull/95/files#diff-f7fdb7f869853f24152c763c31b9ea03R19

GitHub
77-Add-cleaner-extracting-returns-for-conditionals-with-return-as-last-statement-in-the-two-branches by jecisc · Pull Request #95 · jecisc/Chanel
Add cleaner extracting return from conditions. Also disable Epicea to run tests Fixes #77 Fixes #94