rubocop / rubocop-factory_bot

Code style checking for factory_bot files.
https://docs.rubocop.org/rubocop-factory_bot
MIT License
47 stars 13 forks source link

rubocop-factory_bot does not work with rubocop version 1.64.1 #128

Closed Piioo closed 4 months ago

Piioo commented 4 months ago

I using rubocop with rubocop-factory_bot.

rubocop.yml

require:
  - rubocop-rails
  - rubocop-rspec
  - rubocop-factory_bot

Gemfile and Gemfile.lock

# Gemfile
  gem 'rubocop-factory_bot', require: false

# Gemfile.lock
    rubocop (1.64.1)
    rubocop-factory_bot (2.26.1)
      rubocop (~> 1.61)

When I run bundle exec rubocop I got:

✗ bundle exec rubocop
cannot load such file -- rubocop-factory_bot
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/feature_loader.rb:46:in `rescue in rescue in load'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/feature_loader.rb:39:in `rescue in load'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/feature_loader.rb:32:in `load'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/feature_loader.rb:21:in `load'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/config_loader_resolver.rb:14:in `block (2 levels) in resolve_requires'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/config_loader_resolver.rb:13:in `each'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/config_loader_resolver.rb:13:in `block in resolve_requires'
<internal:kernel>:90:in `tap'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/config_loader_resolver.rb:12:in `resolve_requires'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/config_loader.rb:52:in `load_file'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/config_loader.rb:111:in `configuration_from_file'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/config_store.rb:68:in `for_dir'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/config_store.rb:47:in `for_pwd'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cli.rb:149:in `parallel_by_default!'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cli.rb:49:in `block in run'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cli.rb:81:in `profile_if_needed'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cli.rb:43:in `run'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/server_command/exec.rb:22:in `run'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/server_command/base.rb:24:in `block in run'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/server_command/base.rb:23:in `chdir'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/server_command/base.rb:23:in `run'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/socket_reader.rb:33:in `block in read!'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/helper.rb:26:in `redirect'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/socket_reader.rb:28:in `read!'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/core.rb:86:in `read_socket'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/core.rb:61:in `block in process_input'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/cache.rb:140:in `write_pid_file'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/core.rb:60:in `process_input'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/core.rb:49:in `block in detach_server'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/core.rb:46:in `fork'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/core.rb:46:in `detach_server'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/core.rb:38:in `start'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/client_command/start.rb:42:in `block in run'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/cache.rb:127:in `acquire_lock'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/client_command/start.rb:29:in `run'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/cli.rb:93:in `run_command'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/cli.rb:83:in `process_arguments'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/server/cli.rb:49:in `run'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/exe/rubocop:8:in `<top (required)>'
/Users/pisz/.asdf/installs/ruby/3.3.2/bin/rubocop:25:in `load'
/Users/pisz/.asdf/installs/ruby/3.3.2/bin/rubocop:25:in `<top (required)>'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/lib/bundler/cli/exec.rb:58:in `load'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/lib/bundler/cli/exec.rb:58:in `kernel_load'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/lib/bundler/cli/exec.rb:23:in `run'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/lib/bundler/cli.rb:492:in `exec'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/lib/bundler/cli.rb:34:in `dispatch'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/lib/bundler/cli.rb:28:in `start'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/exe/bundle:37:in `block in <top (required)>'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/bundler-2.4.20/exe/bundle:29:in `<top (required)>'
pirj commented 4 months ago

You require rubocop-rspec in your .rubocop.yml. Do you have it in your Gemfile?

Piioo commented 4 months ago

yes,

  gem 'rubocop', require: false
  gem 'rubocop-performance', require: false
  gem 'rubocop-rails', '~> 2.21', require: false
  gem 'rubocop-rspec', require: false
  gem 'rubocop-factory_bot', require: false
Piioo commented 4 months ago

Maybe it is my system :/

When I add a binding.pry to the place where the error happen, it change nothing. I have to check

Piioo commented 4 months ago

But it is fine when I require it in console:


[4] pry(main)> require 'rubocop-factory_bot'
=> false

When I remove rubocop-factory_bot from .rubocop.yml then rubocop works too

Piioo commented 4 months ago

ok, it is working on a fresh rails app. I need to search the problem on my system

midtownkc commented 4 months ago

I also am experiencing this issue. files are present in Gemfile & rubocop.yml

pirj commented 4 months ago

What if you set the breakpoint in /Users/pisz/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/rubocop-1.64.1/lib/rubocop/feature_loader.rb:46? https://github.com/rubocop/rubocop/blob/f33b940844b777ea6414f05fa0225771f6eb0913/lib/rubocop/feature_loader.rb#L46

What are the values for ‘target’, ‘e.path’, ‘namespaced_target’ etc?

Piioo commented 4 months ago

ok, found the problem

https://docs.rubocop.org/rubocop/usage/caching.html

I had to remove the rubocop cache:

/Users/pisz/.cache/rubocop_cache

After this rubocop has reloaded the whole files again.

I do not know why this is there and maybe it is a bug in rubocop. I will report it there.

Earlopain commented 4 months ago

I'm fairly sure this is caused by server mode, see https://github.com/rubocop/rubocop/issues/12557