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
Conversation
Looks very promising! A couple of generic suggestions: 1.) Don't forget to require the detector in lib/reek/smells.rb |
# @return [Array<SmellWarning>] | ||
def inspect(ctx) | ||
_class_node, ancestor_node, _body_node = ctx.exp.to_a | ||
return [] if ancestor_node.nil? |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
I'm thinking that |
@troessner re. an integration test, do you mean using Cucumber? Should I add some code containing this smell to the |
No, we shouldn't touch those since they exist in the wild so this would be very confusing. |
79acd6b
to
a38c4e9
Compare
Sorry for blending in but I'm interested in this feature. How is that going? |
@troessner I'm interested in this specific smell detector. |
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? |
@andyw8 I think the implementation is okay. Keep up with this great work :) |
Apologies, the replies for this were filtered out of my inbox. Thanks for taking over @waldyr. |
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.