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

Fix an error for unrecognized cop or department RSpecRails/HttpStatus when also using rubocop-rails #14

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fix a `NameError` by Cross-Referencing. ([@ydah])
- Fix an error for `RSpecRails/HttpStatus` when no rack gem is loaded with rubocop-rspec. ([@ydah])
- Fix an error for unrecognized cop or department `RSpecRails/HttpStatus` when also using rubocop-rails. ([@ydah])

## 2.28.1 (2024-03-29)

Expand Down
17 changes: 17 additions & 0 deletions lib/rubocop-rspec_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,20 @@

project_root = File.join(__dir__, '..')
RuboCop::ConfigLoader.inject_defaults!(project_root)

# FIXME: This is a workaround for the following issue:
# https://github.com/rubocop/rubocop-rspec_rails/issues/8
module RuboCop
module Cop
class AmbiguousCopName # rubocop:disable Style/Documentation
prepend(Module.new do
def qualified_cop_name(name, path, warn: true)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memo) There are two possibilities: Rails/HttpStatus or RSpecRails/HttpStatus, which causes an AmbiguousCopName Error. So, as a work around, if name is' RSpec/Rails/HttpStatus', it is rigged so that an AmbiguousCopName Error does not occur.

Error: Ambiguous cop name `RSpec/Rails/HttpStatus` used in /ydah/sandbox_capybara_with_rspec/.rubocop.yml needs department qualifier. Did you mean Rails/HttpStatus or RSpecRails/HttpStatus?

Refs: https://github.com/rubocop/rubocop/blob/97814aa1628789c338e66da7c201fe46dd6aa469/lib/rubocop/cop/registry.rb#L133-L145

return super unless name == 'RSpec/Rails/HttpStatus'

badge = Badge.parse(name)
resolve_badge(badge, qualify_badge(badge).first, path)
end
end)
end
end
end