From 992d923dec575deda0ad3feaf120c73951650ed9 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Fri, 12 Apr 2024 13:02:42 +0900 Subject: [PATCH] Fix a build error This PR prevents the following build error: ```console NoMethodError: undefined method `cop_name' for nil # ./lib/rubocop/cop/badge.rb:52:in `match?' # ./lib/rubocop/cop/registry.rb:300:in `resolve_badge' # ./vendor/bundle/ruby/3.3.0/gems/rubocop-rspec_rails-2.28.3/lib/rubocop-rspec_rails.rb:30:in `qualified_cop_name' ``` https://github.com/rubocop/rubocop/actions/runs/8656558784/job/23737409762 This build error is due to a monkey patch in rubocop-rails_rails: https://github.com/rubocop/rubocop-rspec_rails/pull/14 The monkey patch in rubocop-rspec_rails should also be fixed, but this patch prevents RuboCop from failing due to dependencies. RuboCop does not depend on Rails, so the ideal solution would be to remove the dependency on rubocop-rspec_rails gem. However, this is not possible currently because rubocop-rspec is still dependent on it. --- lib/rubocop/cop/registry.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/rubocop/cop/registry.rb b/lib/rubocop/cop/registry.rb index 12189c2caec15..d6c752c0d3bf1 100644 --- a/lib/rubocop/cop/registry.rb +++ b/lib/rubocop/cop/registry.rb @@ -297,6 +297,10 @@ def with(cops) end def resolve_badge(given_badge, real_badge, source_path) + # Prevents the following build error: + # https://github.com/rubocop/rubocop/actions/runs/8656558784/job/23737409762 + return '' if read_badge.nil? + unless given_badge.match?(real_badge) path = PathUtil.smart_path(source_path) warn "#{path}: #{given_badge} has the wrong namespace - " \