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

bundle exec required for running rubocop 1.63.0 and rubocop-rails #12823

Closed
yatryan opened this issue Apr 8, 2024 · 11 comments · Fixed by #12826
Closed

bundle exec required for running rubocop 1.63.0 and rubocop-rails #12823

yatryan opened this issue Apr 8, 2024 · 11 comments · Fixed by #12826
Labels
bug high priority A ticket considered important by RuboCop's Core Team

Comments

@yatryan
Copy link

yatryan commented Apr 8, 2024

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

  1. Create new rails project, add rubocop 1.63.0 and latest rubocop-rails to Gemfile
  2. rubocop --only Rails --require rubocop-rails will fail to run
  3. bundle 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]
@100terres
Copy link

100terres commented Apr 8, 2024

Could it be related to this PR (#12186)?

@100terres
Copy link

100terres commented Apr 8, 2024

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.

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 8, 2024

//cc @amomchilov

@bbatsov bbatsov added bug high priority A ticket considered important by RuboCop's Core Team labels Apr 8, 2024
@paulomcnally
Copy link

ℹ️ 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

@paulomcnally
Copy link

paulomcnally commented Apr 8, 2024

caac002#diff-ea315f91121985f09990cfdec25432799284584bcf6778086f4dae8f2a0176eaL37

Maybe 👀

lockfile_path ||= defined?(::Bundler) ? ::Bundler.default_lockfile : nil

@amomchilov
Copy link
Contributor

Looking into this!

amomchilov added a commit to amomchilov/rubocop that referenced this issue Apr 9, 2024
Fixes the broken reference to `Bundler` on line 66
amomchilov added a commit to amomchilov/rubocop that referenced this issue Apr 9, 2024
Fixes the broken reference to `Bundler` on line 66
@amomchilov
Copy link
Contributor

amomchilov commented Apr 9, 2024

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:

  1. 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'
  2. 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'

julienbourdeau added a commit to getlago/lago-api that referenced this issue Apr 9, 2024
Yesterday, all our `pronto` actions started [failing like
this](https://github.com/getlago/lago-api/actions/runs/8600901566/job/23566843917?pr=1854).

It turned out that there was a bug introduced in rubocop, which made it
incompatible with `rubocop-rails`. A
[fix](rubocop/rubocop#12826) seems on the way.

rubocop/rubocop#12823

One way to mitigate this is to use `bundle exec rubocop` instead of
global `rubocop`. We don't have pronto in our Gemfile so let's move to
regular rubocop for now.

Ideally, we'd like to move to checks like this:
#1856

Note: It's necessary to exit if there is no files to run because you can
run rubocop on the entire codebase today.
bbatsov pushed a commit that referenced this issue Apr 9, 2024
Fixes the broken reference to `Bundler` on line 66
@bmulholland
Copy link

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 🙏

@yatryan
Copy link
Author

yatryan commented Apr 10, 2024

@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'

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 10, 2024

@bmulholland I'll cut a new release within the next hour.

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 10, 2024

The new release is out https://github.com/rubocop/rubocop/releases/tag/v1.63.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug high priority A ticket considered important by RuboCop's Core Team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants