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

WIP: Add SubclassedFromCoreClass smell detector #917

Closed
wants to merge 6 commits into from

Conversation

andyw8
Copy link
Collaborator

@andyw8 andyw8 commented Apr 29, 2016

Addresses #907

Opening for early feedback. There's one pending spec, I'm still getting the hang of Parser so any advice would be welcome.

@andyw8 andyw8 changed the title WIP: Subclassed from core class WIP: Add SubclassedFromCoreClass smell detector Apr 29, 2016
@troessner
Copy link
Owner

Looks very promising!

A couple of generic suggestions:

1.) Don't forget to require the detector in lib/reek/smells.rb
2.) An integration test would be great (that one would have also caught [1]

# @return [Array<SmellWarning>]
def inspect(ctx)
_class_node, ancestor_node, _body_node = ctx.exp.to_a
return [] if ancestor_node.nil?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this to a new predicate method ancestor? on exp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that be Reek::AST::Node?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those extensions are defined in modules under Reek::AST::SexpExtensions.

Copy link
Collaborator Author

@andyw8 andyw8 May 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvz I'm having trouble understanding how to structure this. Could you give me some guidance? (cc @troessner)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The modules under SexpExtensions are included in the classes representing the AST nodes. The modules that is included depends on the node type.

So nodes of type :class get ClassNode included, which is defined in lib/reek/ast/sexp_extensions/module.rb. In fact, you can see there that the relevant methods are defined in ModuleNodeBase, because many methods that are relevant for :class are also relevant for :module and :casgn nodes.

Long story short, you would probably want to define ancestor on ClassNode to start with, and then change the code above to:

  exp = ctx.exp
  return [] unless exp.ancestor

@andyw8
Copy link
Collaborator Author

andyw8 commented Apr 30, 2016

I'm thinking that SubclassedFromCoreClass may not be a good name, since there are cases where subclassing a core class is the correct thing to do, e.g. with RuntimeError.

@andyw8
Copy link
Collaborator Author

andyw8 commented Apr 30, 2016

@troessner re. an integration test, do you mean using Cucumber? Should I add some code containing this smell to the inline.rb sample file?

@troessner
Copy link
Owner

@troessner re. an integration test, do you mean using Cucumber? Should I add some code containing this smell to the inline.rb sample file?

No, we shouldn't touch those since they exist in the wild so this would be very confusing.
You can e.g. check out this feature to check out the current idiomatic Reek way.

@andyw8 andyw8 force-pushed the subclassed-from-core-class branch from 79acd6b to a38c4e9 Compare May 7, 2016 18:38
@waldyr
Copy link
Collaborator

waldyr commented May 15, 2016

Sorry for blending in but I'm interested in this feature. How is that going?

@troessner
Copy link
Owner

I think @andyw8 is the only one who can answer this question at the moment ;)

@waldyr are you interested in how smell detectors are structured (i can explain that on request) or in this specific smell detector?

@waldyr
Copy link
Collaborator

waldyr commented May 16, 2016

@troessner I'm interested in this specific smell detector.

@andyw8
Copy link
Collaborator Author

andyw8 commented May 18, 2016

Hi @waldyr, thanks for your interest. I have a lot on at the moment, but hope to get back to this next week. Do you have any thoughts on the implementation so far?

@waldyr
Copy link
Collaborator

waldyr commented May 18, 2016

@andyw8 I think the implementation is okay. Keep up with this great work :)

@troessner
Copy link
Owner

@andyw8 if you don't have the time, no problem, but let's not kill @waldyr impulse and motivation by inactivity. Let's deprecate this PR in favor of #945 - @waldyr care to over and push your PR forward?
I'll happily review and help you as soon as something is reviewable.

@troessner
Copy link
Owner

Closing this one in favor of #954 - thanks for getting this started @andyw8 !

@troessner troessner closed this Jun 18, 2016
@troessner troessner deleted the subclassed-from-core-class branch June 18, 2016 19:42
@andyw8
Copy link
Collaborator Author

andyw8 commented Jun 21, 2016

Apologies, the replies for this were filtered out of my inbox. Thanks for taking over @waldyr.

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

Successfully merging this pull request may close these issues.

None yet

4 participants