-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add new Lint/EmptyClass
cop
#9001
Conversation
I'm wondering if this shouldn't be part of a more generic |
Ha, I was 100% sure that there is already a cop for empty classes 😄 Empty modules and metaclasses are always useless, while empty classes are sometimes used and useful (for example, empty classes for some results Maybe there is a better name for the cop then, if we will combine checks for classes, modules and metaclasses? |
Metaclasses: yes. Modules: not necessarily: # main.rb:
module MyNameSpace
end
require_relative 'foo'
require_relative 'bar'
# ...
# foo.rb:
class MyNameSpace::Foo
end
# same with bar |
Still, I've never seen a namespace module created empty, but I guess someone might be using them in this way. We can always have a flag for this. |
Here's one I wrote myself. I have an issue with cops that flag code that is either valid or innocuous, especially when rare. The extremely negative feelings it might generate can completely outweigh the (potentially negligible) gain. Remember, you've never seen an empty module, so clearly it's not a common mistake that gains much from being flagged and corrected. |
Ah, forgot about this case. I have seen a couple of examples like this. Thanks for the link to keynote, haven't seen that. It was fun 😄 Personally, I find The cops I absolutely hate, when enabled, are The first of them leads to code like return ... if ...
return ... unless ...
3 more times return ...
do_something Even, forcing me to write something like def method
return unless condition
do_something
end drives me mad a little. |
33282e9
to
376b4ff
Compare
Changed the cop's name to |
Simple is good. :-) Thanks! |
This cop checks for metaclasses without a body.