Skip to content

Commit

Permalink
Adjust config formatting to keep styleguide links
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Jan 4, 2022
1 parent 6c792e2 commit 29d7fc6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/rubocop/rspec/config_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module RSpec
class ConfigFormatter
EXTENSION_ROOT_DEPARTMENT = %r{^(RSpec/)}.freeze
SUBDEPARTMENTS = %(RSpec/Capybara RSpec/FactoryBot RSpec/Rails)
STYLE_GUIDE_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'
COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'

def initialize(config, descriptions)
@config = config
Expand All @@ -27,16 +27,21 @@ def unified_config
cops.each_with_object(config.dup) do |cop, unified|
next if SUBDEPARTMENTS.include?(cop)

unified[cop] = config.fetch(cop)
.merge(descriptions.fetch(cop))
.merge('StyleGuide' => STYLE_GUIDE_BASE_URL + cop.sub('RSpec/', ''))
unified[cop].merge!(descriptions.fetch(cop))
unless unified[cop]['StyleGuide']
unified[cop].merge!('StyleGuide' => cop_doc_url(cop))
end
end
end

def cops
(descriptions.keys | config.keys).grep(EXTENSION_ROOT_DEPARTMENT)
end

def cop_doc_url(cop)
COP_DOC_BASE_URL + cop.sub('RSpec/', '')
end

attr_reader :config, :descriptions
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/rspec/config_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
},
'RSpec/Bar' => {
'Enabled' => true
},
'RSpec/Baz' => {
'Enabled' => true,
'StyleGuide' => '#buzz'
}
}
end
Expand All @@ -25,6 +29,9 @@
},
'RSpec/Bar' => {
'Description' => 'Wow'
},
'RSpec/Baz' => {
'Description' => 'Woof'
}
}
end
Expand All @@ -47,6 +54,11 @@
| Enabled: true
| Description: Wow
| StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Bar
|
|RSpec/Baz:
| Enabled: true
| StyleGuide: "#buzz"
| Description: Woof
YAML
end
end

0 comments on commit 29d7fc6

Please sign in to comment.