anycable / anycable-rails

AnyCable for Ruby on Rails applications
https://anycable.io
MIT License
499 stars 35 forks source link

Extract rubocop rules into separate gem #197

Open taras-viiatyk-yalantis opened 6 months ago

taras-viiatyk-yalantis commented 6 months ago

Hi everyone

Can you extract rubocop rules into separate gem? https://github.com/anycable/anycable-rails/tree/master/lib/anycable/rails/compatibility

The problem

I have a separate group for rubocop inside my Gemfile:

# ...
gem 'anycable-rails'
# ...
group :development, :rubocop do
  gem 'rubocop', require: false
  gem 'rubocop-performance', require: false
  gem 'rubocop-rails', '~> 2.15', '>= 2.15.2', require: false
end
# ...

And the following rubocop config:

# ...
require:
  - rubocop-rails
  - rubocop-performance
  - 'anycable/rails/compatibility/rubocop'
# ...

CI is configured to install only gems needed for rubocop:

BUNDLE_ONLY=rubocop bundle install

Unfortunately the rubocop itself doesn't work with this setup

bundle exec rubocop

because the anycable-rails is not installed cannot load such file -- anycable/rails/compatibility/rubocop

Workaround

So, now I should do something like this to make it work

# ...
group :development, :rubocop do
  gem 'rubocop', require: false
  gem 'rubocop-performance', require: false
  gem 'rubocop-rails', '~> 2.15', '>= 2.15.2', require: false
end

group :development, :test, :production, :rubocop do
  gem 'anycable-rails'
end
# ...

What do I expect?

Ideally, I would expect to have this inside of my Gemfile

# ...
gem 'anycable-rails'
# ...
group :development, :rubocop do
  gem 'rubocop', require: false
  gem 'rubocop-performance', require: false
  gem 'rubocop-rails', '~> 2.15', '>= 2.15.2', require: false
  gem 'rubocop-anycable', require: false 
end
# ...

And this rubocop config

# ...
require:
  - rubocop-rails
  - rubocop-performance
  - rubocop-anycable
# ...

Separate gem will allow me to not load the full gem for the lining step on my CI and keep my Gemfile cleaner.

palkan commented 5 months ago

Hey!

Thanks for the detailed explanation. Makes sense to me. Will work on it after RailsConf (or at RailsConf).