Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user-customizable code critics #16

Open
peteruhnak opened this issue Jul 28, 2015 · 8 comments
Open

user-customizable code critics #16

peteruhnak opened this issue Jul 28, 2015 · 8 comments

Comments

@peteruhnak
Copy link

In Roassal there's very common pattern

el := RTEllipse new
        size: 14;
        color: Color black;
        element

so I am in fact returning an instance of RTElement and not the receiver.
Of course QA says missing ";yourself".

This would require to be able to specify conditions for the code critic, such as
if receiver is subclass of RTShape then don't apply this (yourself) rule

@peteruhnak
Copy link
Author

Another example is (also taken from Roassal)

container @ RTDraggable @ RTResizable.

with critic "Possible three element point".
Again the critic doesn't consider that someone else than a point can name a method @.

@Uko
Copy link
Owner

Uko commented Aug 3, 2015

Thanks for another use-case. Maybe this rule should be removed altogether, as I doubt that it provides actual help.

As a side note:

if someone not knowing Roassal API will look at your code, he/she may think that you are sending something to the result of container @ RTDraggable. But if you will write your code as:

container
  @ RTDraggable;
  @ RTResizable.

it's 100% clear that you are sending messages to container.

@peteruhnak
Copy link
Author

Well then the question is then who is the target user. I would say that people that work with the code regularly need it much more than people that occasionally look at the code and thus it should cater more to them.

So if someone doesn't know Roassal API then I don't think that I want him to touch my roassal-related code. And technically speaking I am sending it to the result, I just know what the result is.

@peteruhnak
Copy link
Author

I have another case:

in PetitParser when creating delegate parsers (subclasses of PPCompositeParser) one would use instance variables to refer to them, however they are never explicitly written to (it is done via metaprogramming), so QA will complain about all the variables.

In addition the critic says "[...] Instance variables not read AND written", which is false, because they are read from.

@Uko
Copy link
Owner

Uko commented Nov 24, 2015

@peteruhnak thanks for mentioning this. I've already noticed that PetitParser is a good place to work on customizability of the rules, as there are many of them that criticize PP as it uses plenty of metaprogramming. As for "Instance variables not read AND written" it's again a very bad naming of the rule that does not explain the real issue. I still have to figure out what the rule does and how to rename it :)

@peteruhnak
Copy link
Author

I would also propose to ignore Refers to class name instead of "self class" rule for class-side example methods. It is in many instances (e.g. Roassal )common use case to copy the code, paste to playground and play with it, so one would have to always fix the name.

Plus the name of the rule doesn't make sense on the class-side, because self class is a metaclass.

@Uko
Copy link
Owner

Uko commented Dec 3, 2015

@peteruhnak can you give me a roassal class for example? So I can get a better understanding

@peteruhnak
Copy link
Author

Looking back through it.... most examples are actually moved to separate *Example, where the problem doesn't arise, so maybe it's just my habit and Alex moves it away once I commit it. :)

Look at the following methods

classes := Object withAllSubclasses select: [ :each | each className beginsWith: 'RT' ] thenCollect: #theMetaClass.
((classes flatCollect: #methods) select: [ :each |
        each selector beginsWith: 'example' ])
        select: [ :each |
    each critics detect: [ :re | re rule isMemberOf: RBRefersToClassRule ] ifFound: [ true ] ifNone: [ false ] ]

For example RTResizable class>>example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants