Rubocop: Deprecate inherited hook for registering cops?

Created on 4 Jan 2017  路  7Comments  路  Source: rubocop-hq/rubocop

Registering cops using the self.inherited hook makes cops pretty difficult to test and is also fairly unfriendly to third party extensions. I've had to do some voodoo in rubocop-rspec to workaround the inherited hook since I wanted to extract out some rubocop-rspec specific behavior into a parent cop class: https://github.com/backus/rubocop-rspec/blob/f8e832d1935167619f405d37b02530d792b9be5f/lib/rubocop/cop/rspec/cop.rb

It is nice not having to worry about registering every new cop so I don't want to remove the inherited hook with something that requires a lot more manual effort. Instead I think something like this would be nice:

# in lib/rubocop.rb after all requires

RuboCop::Cop::Cop.enlist_department(:Style)
RuboCop::Cop::Cop.enlist_department(:Rails)
RuboCop::Cop::Cop.enlist_department(:Performance)
RuboCop::Cop::Cop.enlist_department(:Security)
RuboCop::Cop::Cop.enlist_department(:Metrics)
RuboCop::Cop::Cop.enlist_department(:Lint)
RuboCop::Cop::Cop.enlist_department(:Bundler)
enhancement refactoring stale

Most helpful comment

RuboCop::Cop::Cop

I also wonder how I came up with this brilliant naming - a module and a class sharing the same name. Makes me smile every time. :-)

All 7 comments

Linking this to https://github.com/bbatsov/rubocop/issues/3414 since it seems relevant

Fine by me. I guess this was mostly intended for people who wanted to add some cops locally. Don't remember the details anymore. :-)

Heh yeah seems like it was introduced quite a long time ago https://github.com/bbatsov/rubocop/commit/23e10f3#diff-bb699bbdd39f9057a30af6f90468ef1dR16

Haha. One of the first commits. I remember one thing - back then I had no idea what i was doing. :D

RuboCop::Cop::Cop

I also wonder how I came up with this brilliant naming - a module and a class sharing the same name. Makes me smile every time. :-)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it.

Was this page helpful?
0 / 5 - 0 ratings