Skip to content

Commit

Permalink
Merge pull request #1352 from ydah/support_null_for_config_formatter
Browse files Browse the repository at this point in the history
Support for using `~` when converting null values to `ConfigFormatter`
  • Loading branch information
pirj committed Aug 4, 2022
2 parents 223afd5 + 10c13f7 commit 5416f72
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 18 additions & 2 deletions lib/rubocop/rspec/config_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def dump
.gsub(EXTENSION_ROOT_DEPARTMENT, "\n\\1")
.gsub(*AMENDMENTS, "\n\\0")
.gsub(/^(\s+)- /, '\1 - ')
.gsub('"~"', '~')
end

private
Expand All @@ -30,15 +31,30 @@ def unified_config
next if SUBDEPARTMENTS.include?(cop)
next if AMENDMENTS.include?(cop)

unified[cop].merge!(descriptions.fetch(cop))
unified[cop]['Reference'] = COP_DOC_BASE_URL + cop.sub('RSpec/', '')
replace(cop, unified)
end
end

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

def replace(cop, unified)
replace_nil(unified[cop])
unified[cop].merge!(descriptions.fetch(cop))
unified[cop]['Reference'] = reference(cop)
end

def replace_nil(config)
config.each do |key, value|
config[key] = '~' if value.nil?
end
end

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

attr_reader :config, :descriptions
end
end
Expand Down
4 changes: 3 additions & 1 deletion spec/rubocop/rspec/config_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
'Enabled' => true
},
'RSpec/Bar' => {
'Enabled' => true
'Enabled' => true,
'Nullable' => nil
},
'RSpec/Baz' => {
'Enabled' => true,
Expand Down Expand Up @@ -52,6 +53,7 @@
|
|RSpec/Bar:
| Enabled: true
| Nullable: ~
| Description: Wow
| Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Bar
|
Expand Down

0 comments on commit 5416f72

Please sign in to comment.