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

Error "Ambiguous cop name RSpec/Rails/HttpStatus" with latest rubocop-rspec and rubocop-rspec_rails #18

Closed
mjankowski opened this issue Apr 1, 2024 · 7 comments · Fixed by #25

Comments

@mjankowski
Copy link

mjankowski commented Apr 1, 2024

Following up on conversation here - #9 (comment)

Here's a minimal reproduction case. There are two files: Gemfile, and a minimal .rubocop.yml.

Gemfile:

# frozen_string_literal: true

source 'https://rubygems.org'

gem 'rubocop', require: false
gem 'rubocop-rails', require: false
gem 'rubocop-rspec', require: false

Configuration in .rubocop.yml:

require:
  - rubocop-rails
  - rubocop-rspec

AllCops:
  NewCops: enable

RSpec/Rails/HttpStatus:
  EnforcedStyle: numeric

With this setup, when I run bundle exec rubocop, I get error output:

Error: Ambiguous cop name RSpec/Rails/HttpStatus used in /Users/mjankowski/repos/tester/.rubocop.yml needs department qualifier. Did you mean Rails/HttpStatus or RSpecRails/HttpStatus?

If I comment out the require line for rubocop-rspec in the rubocop.yml (so only rubocop-rails is req'd), the ambiguous error goes away and I get the deprecation warning:

.rubocop.yml: RSpec/Rails/HttpStatus has the wrong namespace - replace it with Rails/HttpStatus

If I restore that line and comment out the rubocop-rails line (so only rubocop-rspec is req'd), I get this warning:

.rubocop.yml: RSpec/Rails/HttpStatus has the wrong namespace - replace it with RSpecRails/HttpStatus

If this matters, I'm running: ruby 3.3.0, rubygems 3.5.7, bundler 2.5.7. Output from bundle list:

Gems included by the bundle:
  * activesupport (7.1.3.2)
  * ast (2.4.2)
  * base64 (0.2.0)
  * bigdecimal (3.1.7)
  * concurrent-ruby (1.2.3)
  * connection_pool (2.4.1)
  * drb (2.2.1)
  * i18n (1.14.4)
  * json (2.7.1)
  * language_server-protocol (3.17.0.3)
  * minitest (5.22.3)
  * mutex_m (0.2.0)
  * parallel (1.24.0)
  * parser (3.3.0.5)
  * racc (1.7.3)
  * rack (3.0.10)
  * rainbow (3.1.1)
  * regexp_parser (2.9.0)
  * rexml (3.2.6)
  * rubocop (1.62.1)
  * rubocop-ast (1.31.2)
  * rubocop-capybara (2.20.0)
  * rubocop-factory_bot (2.25.1)
  * rubocop-rails (2.24.1)
  * rubocop-rspec (2.28.0)
  * rubocop-rspec_rails (2.28.2)
  * ruby-progressbar (1.13.0)
  * tzinfo (2.0.6)
  * unicode-display_width (2.5.0)
Use `bundle info` to print more detailed information about a gem
@mjankowski
Copy link
Author

Maybe more useful debugging ... I add some other obsoleted cops to the config, and removed the httpstatus one. I see output like:

.rubocop.yml: RSpec/Rails/InferredSpecType has the wrong namespace - replace it with RSpecRails/InferredSpecType

and:

Error: The Lint/MultipleCompare cop has been renamed to Lint/MultipleComparison.

(Note how the MultiCompare is the obsoletion error, and the InferredSpecType is a standard namespace warning)

When I add some debug output to the ConfigObsoletion class, it does seem to have the appropriate values in the files class attr, but it doesn't seem to be fully applying/merging those rules. I'm not familiar enough with rubocop internals to know what order these things are supposed to be applied in.

@pirj
Copy link
Member

pirj commented Apr 2, 2024

@dvandersluis do you think you know why this can happen?

@genericsteele
Copy link

We're also still running into this issue. It's blocked a number of our internal gems in CI. We've had to lock rubocop-rspec below v.2.28.0 to avoid it.

@pirj
Copy link
Member

pirj commented Apr 10, 2024

@rubocop/rubocop-rspec do we know what us causing this? Should this be fixed somewhere in RuboCop’s ConfigLoader? What is the course of action? Do we admit our failure with this and recommend to adjust project configs with a minor version update?

@ydah
Copy link
Member

ydah commented Apr 10, 2024

I have found a repository to reproduce and will investigate. Sorry for the delay.

ydah added a commit that referenced this issue Apr 11, 2024
Fix: #18
This PR fixes an error for Ambiguous cop name `RSpec/Rails/HttpStatus` in the `rubocop-rspec_rails` gem.
ydah added a commit that referenced this issue Apr 11, 2024
Fix: #18
This PR fixes an error for Ambiguous cop name `RSpec/Rails/HttpStatus` in the `rubocop-rspec_rails` gem.
@ydah ydah closed this as completed in #25 Apr 11, 2024
@mjankowski
Copy link
Author

After update to rubocop-rspec_rails 2.28.3 I now just see the expected wrong namespace warnings, but no longer get the ambiguous cop warning. Looks good, thanks!

@ydah
Copy link
Member

ydah commented Apr 11, 2024

@mjankowski I really appreciate you reporting this issue! Thank you!

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

Successfully merging a pull request may close this issue.

4 participants