`bundle exec` required for running rubocop 1.63.0 and rubocop-rails
yatryan opened this issue · comments
Expected behavior
Rubocop should run successfully without bundle exec
within a rails project. It appears this is happening since the cut of 1.63.0
, bundle exec rubocop
is expected. If this is now expected behavior (bundle exec
required), the docs should probably be updated.
Actual behavior
Running rubocop
results in a uninitialized constant RuboCop::Lockfile::Bundler
error, while running bundle exec rubocop
completes successfully.
Error without bundle exec
$ rubocop --only Rails --require rubocop-rails
uninitialized constant RuboCop::Lockfile::Bundler
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/lockfile.rb:66:in `rescue in parser'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/lockfile.rb:60:in `parser'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/lockfile.rb:38:in `gem_versions'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/config.rb:332:in `read_gem_versions_from_target_lockfile'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/config.rb:293:in `gem_versions_in_target'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/config.rb:309:in `read_rails_version_from_bundler_lock_file'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/config.rb:304:in `target_rails_version_from_bundler_lock_file'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/config.rb:255:in `target_rails_version'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cop/base.rb:264:in `target_rails_version'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cop/team.rb:182:in `support_target_rails_version?'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cop/team.rb:166:in `block in roundup_relevant_cops'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cop/team.rb:161:in `select'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cop/team.rb:161:in `roundup_relevant_cops'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cop/team.rb:88:in `investigate'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:348:in `block in inspect_file'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:347:in `each'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:347:in `flat_map'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:347:in `inspect_file'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:290:in `block in do_inspection_loop'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:324:in `block in iterate_until_no_changes'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:317:in `loop'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:317:in `iterate_until_no_changes'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:286:in `do_inspection_loop'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:167:in `block in file_offenses'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:192:in `file_offense_cache'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:166:in `file_offenses'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:102:in `block in warm_cache'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/parallel-1.24.0/lib/parallel.rb:627:in `call_with_index'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/parallel-1.24.0/lib/parallel.rb:597:in `process_incoming_jobs'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/parallel-1.24.0/lib/parallel.rb:577:in `block in worker'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/parallel-1.24.0/lib/parallel.rb:568:in `fork'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/parallel-1.24.0/lib/parallel.rb:568:in `worker'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/parallel-1.24.0/lib/parallel.rb:559:in `block in create_workers'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/parallel-1.24.0/lib/parallel.rb:558:in `each'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/parallel-1.24.0/lib/parallel.rb:558:in `each_with_index'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/parallel-1.24.0/lib/parallel.rb:558:in `create_workers'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/parallel-1.24.0/lib/parallel.rb:497:in `work_in_processes'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/parallel-1.24.0/lib/parallel.rb:291:in `map'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/parallel-1.24.0/lib/parallel.rb:235:in `each'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:102:in `warm_cache'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/runner.rb:75:in `run'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cli.rb:118:in `run_command'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cli.rb:125:in `execute_runners'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cli.rb:51:in `block in run'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cli.rb:77:in `profile_if_needed'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/lib/rubocop/cli.rb:43:in `run'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/exe/rubocop:19:in `block in <top (required)>'
/Users/taylorryan/.rvm/rubies/ruby-3.0.6/lib/ruby/3.0.0/benchmark.rb:308:in `realtime'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/gems/rubocop-1.63.0/exe/rubocop:19:in `<top (required)>'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/bin/rubocop:25:in `load'
/Users/taylorryan/.rvm/gems/ruby-3.0.6/bin/rubocop:25:in `<main>'
Success with bundle exec
$ bundle exec rubocop --only Rails --require rubocop-rails
Inspecting 176 files
.....C..C.CC...C...CC..........C.CC.CCC...CCCCCC...............C..CC..............C.....C.................CC.C.....C..C.C...CC........C.........................C...C..C....C.C.
Offenses:
# TRIMMED
176 files inspected, 68 offenses detected, 39 offenses autocorrectable
It seems to be related to these changes: caac002, where we wouldnt hit the rescue
since we already checked for defined?(Bundler)
on line 37
Steps to reproduce the problem
- Create new rails project, add rubocop 1.63.0 and latest rubocop-rails to Gemfile
rubocop --only Rails --require rubocop-rails
will fail to runbundle exec rubocop --only Rails --require rubocop-rails
will succeed
RuboCop version
$ rubocop -V
1.63.0 (using Parser 3.3.0.5, rubocop-ast 1.31.2, running on ruby 3.0.6) [arm64-darwin22]
We are facing a similar issue. On our side the running rubocop
command fails with the uninitialized constant RuboCop::Lockfile::Bundler
error. The bundle exec rubocop
only works when the rubocop server isn't running, but when it's running it fails with the same error.
//cc @amomchilov
ℹ️ This affects github actions.
name: Rubocop
on:
pull_request:
branches: [main]
jobs:
rubocop:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
- name: Install rubocop
run: gem install rubocop rubocop-rails rubocop-rspec
- name: Run Rubocop
run: rubocop
caac002#diff-ea315f91121985f09990cfdec25432799284584bcf6778086f4dae8f2a0176eaL37
Maybe 👀
lockfile_path ||= defined?(::Bundler) ? ::Bundler.default_lockfile : nil
Looking into this!
Apologies for the bug, this didn't get triggered when I tested rubocop
on itself (which doesn't use rubocop-rails
) :)
I fixed this in #12826, which just got merged, hasn't been released yet.
Until that's released, you can workaround this bug in 2 ways:
-
Use that unreleased fix:
# TODO: Unpin version once this PR is released: https://github.com/rubocop/rubocop/pull/12826 gem 'rubocop', github: 'rubocop/rubocop', ref: 'b0c508a6586497d38cab56e99cb19f070e52c59f'
-
Pin to the previous version:
# TODO: Unpin version once this PR is released: https://github.com/rubocop/rubocop/pull/12826 gem 'rubocop', '~> 1.62.1'
Is there a place where we can get notified when a release is out? I'll need to remove the pin from my Gemfile. A simple solution could be a post in this thread, would help me out 🙏
@bmulholland We solved this by using the following pin. Of course, this assumes the next version will fix this.
gem 'rubocop', '~> 1.62', '! 1.63.0'
@bmulholland I'll cut a new release within the next hour.
The new release is out https://github.com/rubocop/rubocop/releases/tag/v1.63.1