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

TooManyMethods false positive with nested classes #1476

Open
eloyesp opened this issue May 13, 2019 · 5 comments
Open

TooManyMethods false positive with nested classes #1476

eloyesp opened this issue May 13, 2019 · 5 comments
Labels

Comments

@eloyesp
Copy link

eloyesp commented May 13, 2019

I'm having false positive with TooManyMethods, with a code that looks like this:

class WeeklyReminder
  attr_reader :user, :week, :result_set, :dates

  WeekPerformance = Struct.new :week, :submitted, :missing do
    def multiple_methods_here
    end
  end

  def other_methods_here
  end
end

# => TooManyMethods: WeeklyReminder has at least (multiple_methods + other_methods_here) methods.

Seems that reek does not catch the context switch when defining methods on the Struct.

Is it possible for it to detect it or should I add a magic comment (or may be just define the struct in other way).

@mvz
Copy link
Collaborator

mvz commented May 13, 2019

Hi @eloyesp, thanks for reporting this. We do intend to support such code in Reek, so this is a bug.

@mvz mvz added the defect label May 13, 2019
@eloyesp
Copy link
Author

eloyesp commented May 13, 2019

I were checking a little bit, but I lack experience with the parser library.

It seems that the AST that should be detected is something like:

s(:casgn, nil, :WeekPerformance,
  s(:block,
    s(:send,
      s(:const, nil, :Struct), :new,
      # struct args to ignore
    s(:args),
    s(:begin,
      # everithing inside is another class (so defs should count towards other class)

But I'm not sure how to implement that.

@mvz
Copy link
Collaborator

mvz commented May 13, 2019

I'll take a look in the coming week. I think we already handle this construction elsewhere, so it shouldn't be too hard to fix this.

@JuanVqz
Copy link
Contributor

JuanVqz commented Oct 18, 2023

Hi! I tried to reproduce it locally but seems to not raise anything.

Am I missing something? or can we close the issue?

image

@mvz mvz changed the title ToManyMethods false positive with nested classes TooManyMethods false positive with nested classes Oct 19, 2023
@troessner
Copy link
Owner

@JuanVqz check out the config for TooManyMethods. I think you just need to put more dummy methods in your example and then this should indeed be falsely reported (since we never fixed that bug)

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

No branches or pull requests

4 participants