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

Can't execute v1.34.0 with error "cannot load such file -- rubocop-rails" #10893

Closed
hiro-teaaa opened this issue Aug 9, 2022 · 11 comments · Fixed by #10894
Closed

Can't execute v1.34.0 with error "cannot load such file -- rubocop-rails" #10893

hiro-teaaa opened this issue Aug 9, 2022 · 11 comments · Fixed by #10894
Labels

Comments

@hiro-teaaa
Copy link

hiro-teaaa commented Aug 9, 2022

I can't run rubocop v1.34.0.
Downgrading to v1.33.0, I could run it correctly.


Expected behavior

In the rails project,

  • execute % rubocop
  • then execute correctly 

Actual behavior

% rubocop --debug
For /path-to/ruby-project: configuration from /path-to/ruby-project/.rubocop.yml
cannot load such file -- rubocop-rails
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/feature_loader.rb:33:in `require'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/feature_loader.rb:33:in `load'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/feature_loader.rb:21:in `load'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_loader_resolver.rb:14:in `block (2 levels) in resolve_requires'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_loader_resolver.rb:13:in `each'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_loader_resolver.rb:13:in `block in resolve_requires'
<internal:kernel>:90:in `tap'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_loader_resolver.rb:12:in `resolve_requires'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_loader.rb:46:in `load_file'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_loader.rb:104:in `configuration_from_file'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_store.rb:68:in `for_dir'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_store.rb:47:in `for_pwd'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/cli.rb:99:in `parallel_by_default!'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/cli.rb:46:in `run'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/exe/rubocop:19:in `block in <top (required)>'
/path-to/.rbenv/versions/3.1.1/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/exe/rubocop:19:in `<top (required)>'
/path-to/.rbenv/versions/3.1.1/bin/rubocop:25:in `load'
/path-to/.rbenv/versions/3.1.1/bin/rubocop:25:in `<main>'
Finished in 0.01386200000001736 seconds

Steps to reproduce the problem

  • Just do %rubocop

RuboCop version

% bundle exec rubocop -V
1.34.0 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 3.1.1 arm64-darwin21)
  - rubocop-rails 2.15.2

@unused
Copy link
Contributor

unused commented Aug 9, 2022

Can confirm this issue. It fails for any require that is placed in the .rubocop.yml config file, works fine when using the cli argument $ rubocop --require rubocop-rails --require rubocop-performance.

@weastur
Copy link

weastur commented Aug 9, 2022

+1

@koic koic added the bug label Aug 9, 2022
@koic
Copy link
Member

koic commented Aug 9, 2022

This error is caused by #10845. It requires backward compatibility.

@koic
Copy link
Member

koic commented Aug 9, 2022

@hiro-teaaa Can you provide configuration around require: in .rubocop.yml?

@hiro-teaaa
Copy link
Author

@koic Thank you for checking in so quickly.

Can you provide configuration around require: in .rubocop.yml?

Sure, here it is

require:
  - rubocop-rails

AllCops:
  TargetRubyVersion: 3.1.1
~~~

Is it enough?

@koic
Copy link
Member

koic commented Aug 9, 2022

@hiro-teaaa OK, It was reproducible. Thank you!

@ShockwaveNN
Copy link
Contributor

@koic I got similar issue with rubocop-performance

Mine .rubocop.yml is here

You could checkout this project, it's fully opensource and failing with latest update

@koic
Copy link
Member

koic commented Aug 9, 2022

JFYI, RuboCop 1.34.1 has been released. Thank you.

@ShockwaveNN
Copy link
Contributor

@koic Thanks for quick fix

r7kamura added a commit to r7kamura/rubocop that referenced this issue Aug 11, 2022
koic added a commit that referenced this issue Aug 11, 2022
[Fix #10893] Fix loading behavior on running without `bundle exec`
@olegantonyan
Copy link

It fails for me with rubocop-performance:

# .rubocop.yml
require:
- rubocop-rake
- rubocop-rails
- rubocop-performance
# Gemfile
  gem 'rubocop', require: false
  gem 'rubocop-performance', require: false
  gem 'rubocop-rails', require: false
  gem 'rubocop-rake', require: false
$ bundle exec rubocop
cannot load such file -- rubocop-performance
/home/oleg/.rbenv/versions/3.2.1/lib64/ruby/gems/3.2.0/gems/rubocop-1.45.1/lib/rubocop/feature_loader.rb:46:in `rescue in rescue in load'
/home/oleg/.rbenv/versions/3.2.1/lib64/ruby/gems/3.2.0/gems/rubocop-1.45.1/lib/rubocop/feature_loader.rb:39:in `rescue in load'

rubocop-rake and rubocop-rails work ok, but not rubocop-performance

$ bundle exec rails c
Loading development environment (Rails 7.1.0.alpha)
[1] pry(main)> require 'rubocop-performance'
=> true

rubocop-1.45.1, bundler 2.4.7, rails master, ruby 3.2.1

@BoutPure
Copy link

Still getting such error with v1.60.2.
I'm adding new rubocop extentions to my Gemfile (ex. 'rubocop-rails') and then to the .rubocop.yml.
And when I try to execute rubocop - oops! cannot load such file.

But! I was able to fix this with rubocop --restart-server.
In the docs I found this: https://docs.rubocop.org/rubocop/usage/server.html#restart-server

The started server does not reload the configuration file. You will need to restart the server when you upgrade RuboCop or change the RuboCop configuration.

paulohenrique-gh added a commit to paulohenrique-gh/rails-repertoire-manager that referenced this issue Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants