-
Notifications
You must be signed in to change notification settings - Fork 281
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
DataClump detection fails when methods are separated by unrelated code #1798
Comments
Hi @le-santos, this detector should work even of there is unrelated code between the offending methods. So this would definitely a bug. Have you checked that it does create a warning when the methods are grouped together? I'm asking because DataClump usually allows clumps of two parameters. So this smell would only be detected if you've lowered the maximum in your configuration. |
@le-santos I just checked this and I was wrong. I have checked your sample with the three methods grouped together and I can confirm that DataClump does detect the clump with two parameters. |
@le-santos in conclusion: Yes, this is a bug and a pull request to fix this would definitely be appreciated. |
Hi @mvz, thanks for the answer! # lib/reek/smell_detectors/data_clump.rb
def candidate_clumps
candidate_methods.each_cons(max_copies + 1).map do |methods|
common_argument_names_for(methods)
end.select do |clump|
clump.length >= min_clump_size
end.uniq
end
def common_argument_names_for(methods)
methods.map(&:arg_names).inject(:&).compact.sort
end Considering a source code as below, def a(x,y); end
def b(x,y); end
def c(z) ; end
def d(x,y); end
The An alternative approach would be to use
There is one caveat, though: this may have some performance impact, since the number of items to iterate will be larger. Do you think this is a concern here? |
Fixed in #1799. |
I came across with a situation where reek's
DataClump
smell detection stopped warning when a new method is added between existing methods that share similar arguments.In order to investigate this I wrote a failing test case. However, before start working on some solution, I'd like to confirm: is this the expected behavior or an issue in smell detection?
The documentation states:
However, it doesn't really specify wether these methods need to be consecutive in the source code. Could someone clarify this requirement?
Target code
Expected behavior
reek --smell DataClump sample.rb
Actual behavior
reek --smell DataClump sample.rb
Nothing to warn.
Ruby and gem versions
The text was updated successfully, but these errors were encountered: