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

Extract rubocop rules into separate gem #197

Closed
taras-viiatyk-yalantis opened this issue May 3, 2024 · 2 comments
Closed

Extract rubocop rules into separate gem #197

taras-viiatyk-yalantis opened this issue May 3, 2024 · 2 comments

Comments

@taras-viiatyk-yalantis
Copy link

taras-viiatyk-yalantis commented May 3, 2024

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
Copy link
Member

palkan commented May 4, 2024

Hey!

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

@palkan
Copy link
Member

palkan commented Dec 13, 2024

Done. Now you should be able to install AnyCable cops via rubocop-anycable-rails.

@palkan palkan closed this as completed Dec 13, 2024
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

2 participants