Skip to content

Commit

Permalink
Merge pull request #1256 from luke-hill/patch-1
Browse files Browse the repository at this point in the history
Exclude all spec blocks from Metrics/BlockLength
  • Loading branch information
pirj authored May 18, 2022
2 parents 2f46bf1 + 05bccb6 commit 0488223
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Metrics/BlockLength:
- rubocop-rspec.gemspec
- Rakefile
- '**/*.rake'
- spec/**/*.rb

Naming/FileName:
Exclude:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Drop Ruby 2.5 support. ([@ydah][])
* Add new `RSpec/ChangeByZero` cop. ([@ydah][])
* Improve `RSpec/ExpectChange` to detect namespaced and top-level constants. ([@M-Yamashita01][])
* Introduce an amendment to `Metrics/BlockLength` to exclude spec files. ([@luke-hill][])

## 2.10.0 (2022-04-19)

Expand Down Expand Up @@ -686,3 +687,4 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@ydah]: https://github.com/ydah
[@t3h2mas]: https://github.com/t3h2mas
[@M-Yamashita01]: https://github.com/M-Yamashita01
[@luke-hill]: https://github.com/luke-hill
8 changes: 8 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ RSpec:
- subject
- subject!

Metrics/BlockLength:
inherit_mode:
merge:
- Exclude
Exclude:
- "**/*_spec.rb"
- "**/spec/**/*"

RSpec/AlignLeftLetBrace:
Description: Checks that left braces for adjacent single line lets are aligned.
Enabled: false
Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/rspec/config_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module RSpec
class ConfigFormatter
EXTENSION_ROOT_DEPARTMENT = %r{^(RSpec/)}.freeze
SUBDEPARTMENTS = %(RSpec/Capybara RSpec/FactoryBot RSpec/Rails)
AMENDMENTS = %(Metrics/BlockLength)
COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'

def initialize(config, descriptions)
Expand All @@ -18,6 +19,7 @@ def initialize(config, descriptions)
def dump
YAML.dump(unified_config)
.gsub(EXTENSION_ROOT_DEPARTMENT, "\n\\1")
.gsub(*AMENDMENTS, "\n\\0")
.gsub(/^(\s+)- /, '\1 - ')
end

Expand All @@ -26,6 +28,7 @@ def dump
def unified_config
cops.each_with_object(config.dup) do |cop, unified|
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/', '')
Expand Down
5 changes: 3 additions & 2 deletions spec/project/default_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def cop_configuration(config_key)
end
end

it 'has configuration for all cops' do
expect(default_config.keys).to match_array(config_keys)
it 'has configuration for all cops and amendments' do
expect(default_config.keys)
.to match_array([*config_keys, 'Metrics/BlockLength'])
end

it 'sorts configuration keys alphabetically', :pending do
Expand Down

0 comments on commit 0488223

Please sign in to comment.