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

ClassAndModuleChildren incorrectly flags classes with a single method #1094

Closed
CyborgMaster opened this issue May 18, 2014 · 5 comments
Closed

Comments

@CyborgMaster
Copy link

I like the compact style of class and method definition and therefore have the following in my .rubocop.yml:

ClassAndModuleChildren:
  EnforcedStyle: compact

However this erroneously flags the following module:

module TimeCopMinitestPlugin
  def after_teardown
    Timecop.return
    super
  end
end

with this offense message:

test/test_helper.rb:19:8: C: Use compact module/class definition instead of nested style.
module TimeCopMinitestPlugin
       ^^^^^^^^^^^^^^^^^^^^^

It seems as if it is detecting that the class has a single child and therefore prompting me to try and combine it. This works for classes/modules with a single inner class/module, but is impossible when the contents is a method.

The offense should not be reported if the single child is not a class/module.

@bbatsov
Copy link
Collaborator

bbatsov commented May 18, 2014

Yep, this definitely looks like a bug.

@CyborgMaster
Copy link
Author

Glad to know it's not just me :-)

@geniou
Copy link
Contributor

geniou commented May 18, 2014

I can take a look, if you like.

@bbatsov
Copy link
Collaborator

bbatsov commented May 18, 2014

@geniou That would be great!

bbatsov added a commit that referenced this issue May 18, 2014
…_method

[Fixes #1094] Fix bug in ClassAndModuleChildren
@CyborgMaster
Copy link
Author

Wow you guys are super fast!! I'm impressed. Thanks! Now how about a bugfix release to RubyGems?

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

No branches or pull requests

3 participants