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

Autocorrect: contextual causing error #1916

Closed
gavindidrichsen opened this issue Jun 10, 2024 · 8 comments
Closed

Autocorrect: contextual causing error #1916

gavindidrichsen opened this issue Jun 10, 2024 · 8 comments

Comments

@gavindidrichsen
Copy link

The latest versions of rubocop-factory_bot and rubocop-respec_rails are causing rubocop-rspec to break with something like the following:

➜  dependency_checker git:(main) bundle exec rubocop
Error: Property AutoCorrect of cop FactoryBot/CreateList is supposed to be a boolean and contextual is not.
➜  dependency_checker git:(main) 

Manually correcting the above gems fixes the issue, e.g.,

➜  gems git:(main) ✗ git diff
diff --git a/rubocop-factory_bot-2.26.0/config/default.yml b/rubocop-factory_bot-2.26.0/config/default.yml
index 24d5ebb..60827e7 100644
--- a/rubocop-factory_bot-2.26.0/config/default.yml
+++ b/rubocop-factory_bot-2.26.0/config/default.yml
@@ -49,7 +49,7 @@ FactoryBot/ConsistentParenthesesStyle:
 FactoryBot/CreateList:
   Description: Checks for create_list usage.
   Enabled: true
-  AutoCorrect: contextual
+  AutoCorrect: false
   Include:
     - "**/*_spec.rb"
     - "**/spec/**/*"
diff --git a/rubocop-rspec_rails-2.29.0/config/default.yml b/rubocop-rspec_rails-2.29.0/config/default.yml
index 51ec888..a39bd20 100644
--- a/rubocop-rspec_rails-2.29.0/config/default.yml
+++ b/rubocop-rspec_rails-2.29.0/config/default.yml
@@ -66,7 +66,7 @@ RSpecRails/MinitestAssertions:
 
 RSpecRails/NegationBeValid:
   Description: Enforces use of `be_invalid` or `not_to` for negated be_valid.
-  AutoCorrect: contextual
+  AutoCorrect: false
   Safe: false
   EnforcedStyle: not_to
   SupportedStyles:
➜  gems git:(main) ✗ pwd
/Users/gavin.didrichsen/@REFERENCES/github/app/development/tools/puppet/@products/devx_tools/repos/dependency_checker/.direnv/ruby/gems/ruby/3.3.0/gems
➜  gems git:(main) ✗ 

Given this repository as an example, puppetlabs/dependency_checker, I can see from the Gemspec.lock the rubocop-rspec seems to be pulling the above dependencies in.

    rubocop-rspec (2.30.0)
      rubocop (~> 1.40)
      rubocop-capybara (~> 2.17)
      rubocop-factory_bot (~> 2.22)
      rubocop-rspec_rails (~> 2.28)

Excluding the lates versions as below fixes the issue:

gem 'rubocop-factory_bot', '!= 2.26.0', require: false
gem 'rubocop-rspec_rails', '!= 2.29.0', require: false
@pirj
Copy link
Member

pirj commented Jun 10, 2024

A workaround would be to update rubocop to a bersion that supports “contextual”.

Do we need to bump the dependency like we planned to here? #1901

Wondering why #1882 didn’t work? Wondering why ‘bundle install’ output is so dry https://github.com/rubocop/rubocop-rspec/actions/runs/9148652715/job/25151426029

@bquorning
Copy link
Collaborator

Wondering why #1882 didn’t work? Wondering why ‘bundle install’ output is so dry https://github.com/rubocop/rubocop-rspec/actions/runs/9148652715/job/25151426029

Confirming that CI testing with the oldest RuboCop version does indeed work; see #1920.

The problem must be elsewhere.

@ydah
Copy link
Member

ydah commented Jun 11, 2024

I ran the following on local:
https://github.com/puppetlabs/dependency_checker

Revert to hacks for rubocop-factory_bot and rubocop-rspec_rails

diff --git a/Gemfile b/Gemfile
index 5985c04..18d0b4a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -15,6 +15,4 @@ group :test do
   gem 'rubocop', '~> 1.50.0', require: false
   gem 'rubocop-performance', '~> 1.16', require: false
   gem 'rubocop-rspec', '~> 2.19', require: false
-  gem 'rubocop-factory_bot', '!= 2.26.0', require: false
-  gem 'rubocop-rspec_rails', '!= 2.29.0', require: false
 end
❯ bundle exec rubocop -V
/ydah/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rubocop-1.50.2/lib/rubocop/formatter/html_formatter.rb:3: warning: base64 was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.4.0. Add base64 to your Gemfile or gemspec. Also contact author of rubocop-1.50.2 to add base64 into its gemspec.
Error: Property AutoCorrect of cop FactoryBot/CreateList is supposed to be a boolean and contextual is not.

Change to gem 'rubocop', '~> 1.61.0', require: false

diff --git a/Gemfile b/Gemfile
index 5985c04..2a75e86 100644
--- a/Gemfile
+++ b/Gemfile
@@ -12,9 +12,7 @@ group :test do
   gem 'simplecov', require: false
   gem 'simplecov-console', require: false
   gem 'rspec', '~> 3.0', require: false
-  gem 'rubocop', '~> 1.50.0', require: false
+  gem 'rubocop', '~> 1.61.0', require: false
   gem 'rubocop-performance', '~> 1.16', require: false
   gem 'rubocop-rspec', '~> 2.19', require: false
-  gem 'rubocop-factory_bot', '!= 2.26.0', require: false
-  gem 'rubocop-rspec_rails', '!= 2.29.0', require: false
 end
❯ bundle exec rubocop -V
1.61.0 (using Parser 3.3.2.0, rubocop-ast 1.31.3, running on ruby 3.3.0) [arm64-darwin23]
  - rubocop-performance 1.21.0
  - rubocop-rspec 2.31.0

@ydah
Copy link
Member

ydah commented Jun 11, 2024

I have not yet figured out why this happens but at least v1.61 or higher seems to solve it.

@jminterwebs
Copy link

Having the same issue setting to 1.61 does not fix the issue.

@bquorning
Copy link
Collaborator

Can the problem solved by upgrading to rubocop-rspec v3.0.1?

@jminterwebs
Copy link

v3.0.1 appears to have fixed it all.

@ydah
Copy link
Member

ydah commented Jun 11, 2024

@ydah ydah closed this as completed Jun 11, 2024
dosas added a commit to ATIX-AG/fog-proxmox that referenced this issue Jun 20, 2024
Property AutoCorrect of cop FactoryBot/CreateList is supposed to be a boolean and contextual is not

by setting upper limit for
* rubocop-factory_bot
* rubocop-rspec_rails

rubocop/rubocop-rspec#1916
Manisha15 pushed a commit to fog/fog-proxmox that referenced this issue Jun 20, 2024
Property AutoCorrect of cop FactoryBot/CreateList is supposed to be a boolean and contextual is not

by setting upper limit for
* rubocop-factory_bot
* rubocop-rspec_rails

rubocop/rubocop-rspec#1916
Geromendez135 pushed a commit to Geromendez135/ruby that referenced this issue Jul 16, 2024
error from said version of rubocop:
RuboCop::ValidationError:
  Property AutoCorrect of cop FactoryBot/CreateList is supposed to be a boolean and contextual is not.

version `1.61` fixes that issue, allowing all tests to pass.

found that solution in this issue:
rubocop/rubocop-rspec#1916
from rubocop-rspec, where they were experiencing the same
error, and updating rubocop to 1.61, solved the issue.
However they don't appear to know the culprit of this.
Geromendez135 pushed a commit to Geromendez135/ruby that referenced this issue Jul 16, 2024
error from said version of rubocop:
RuboCop::ValidationError:
  Property AutoCorrect of cop FactoryBot/CreateList is supposed to be a boolean and contextual is not.

version `1.61` of `rubocop` fixes that issue, allowing all tests to pass.

found that solution in this issue:
rubocop/rubocop-rspec#1916
from rubocop-rspec, where they were experiencing the same
error and updating rubocop to 1.61, solved the issue.
However they don't appear to know the culprit of this.
Geromendez135 added a commit to Geromendez135/ruby that referenced this issue Jul 16, 2024
error from said version of rubocop:
RuboCop::ValidationError:
  Property AutoCorrect of cop FactoryBot/CreateList is supposed to be a boolean and contextual is not.

version `1.61` of `rubocop` fixes that issue, allowing all tests to pass.

found that solution in this issue:
rubocop/rubocop-rspec#1916
from rubocop-rspec, where they were experiencing the same
error and updating rubocop to 1.61, solved the issue.
However they don't appear to know the culprit of this.
Geromendez135 added a commit to Geromendez135/ruby that referenced this issue Jul 16, 2024
error from said version of rubocop:
RuboCop::ValidationError:
  Property AutoCorrect of cop FactoryBot/CreateList is supposed to be a boolean and contextual is not.

version `1.61` of `rubocop` fixes that issue, allowing all tests to pass.

found that solution in this issue:
rubocop/rubocop-rspec#1916
from rubocop-rspec, where they were experiencing the same
error and updating rubocop to 1.61, solved the issue.
However they don't appear to know the culprit of this.
Geromendez135 added a commit to Geromendez135/ruby that referenced this issue Jul 16, 2024
error from said version of rubocop:
RuboCop::ValidationError:
  Property AutoCorrect of cop FactoryBot/CreateList is supposed to be a boolean and contextual is not.

version `1.61` of `rubocop` fixes that issue, allowing all tests to pass.

found that solution in this issue:
rubocop/rubocop-rspec#1916
from rubocop-rspec, where they were experiencing the same
error and updating rubocop to 1.61, solved the issue.
However they don't appear to know the culprit of this.
Geromendez135 added a commit to Geromendez135/ruby that referenced this issue Jul 16, 2024
error from said version of rubocop:
RuboCop::ValidationError:
  Property AutoCorrect of cop FactoryBot/CreateList is supposed to be a boolean and contextual is not.

version `1.61` of `rubocop` fixes that issue, allowing all tests to pass.

found that solution in this issue:
rubocop/rubocop-rspec#1916
from rubocop-rspec, where they were experiencing the same
error and updating rubocop to 1.61, solved the issue.
However they don't appear to know the culprit of this.
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

5 participants