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 default config for sub-departments #1163

Merged
merged 1 commit into from Oct 5, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -24,6 +24,7 @@
* Add new `RSpec/IdenticalEqualityAssertion` cop. ([@tejasbubane][])
* Add `RSpec/Rails/AvoidSetupHook` cop. ([@paydaylight][])
* Fix false negative in `RSpec/ExpectChange` cop with block style and chained method call. ([@tejasbubane][])
* Fix `Include` configuration for sub-departments. ([@pirj][])

## 2.3.0 (2021-04-28)

Expand Down
19 changes: 17 additions & 2 deletions config/default.yml
@@ -1,10 +1,10 @@
---
RSpec:
Enabled: true
Include:
Include: &1
Copy link
Member

Choose a reason for hiding this comment

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

It seems that this could be named, e.g. alphanumeric. Might make the file less scary, if it has proper names :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I vaguely recall I planned to do so (to mimic the well-known &default from config/database.yml 😄), but ended up with numbers somehow. Fixed 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, now I recall. It's bin/build_config that does that:

--- a/config/default.yml
+++ b/config/default.yml
@@ -1,10 +1,10 @@
 ---
 RSpec:
   Enabled: true
-  Include: &include
+  Include: &1
     - "**/*_spec.rb"
     - "**/spec/**/*"
-  Language: &language
+  Language: &2
     inherit_mode:
       merge:
         - Expectations

Supposedly, YAML.dump(unified_config) has no respect for named anchors.

I'll revert, otherwise CI is red.

- "**/*_spec.rb"
- "**/spec/**/*"
Language:
Language: &2
inherit_mode:
merge:
- Expectations
Expand Down Expand Up @@ -745,6 +745,11 @@ RSpec/Yield:
VersionAdded: '1.32'
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Yield

RSpec/Capybara:
Enabled: true
Include: *1
Language: *2

RSpec/Capybara/CurrentPathExpectation:
Description: Checks that no expectations are set on Capybara's `current_path`.
Enabled: true
Expand All @@ -767,6 +772,11 @@ RSpec/Capybara/VisibilityMatcher:
VersionChanged: '2.0'
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/VisibilityMatcher

RSpec/FactoryBot:
Enabled: true
Include: *1
Language: *2

RSpec/FactoryBot/AttributeDefinedStatically:
Description: Always declare attribute values as blocks.
Enabled: true
Expand Down Expand Up @@ -806,6 +816,11 @@ RSpec/FactoryBot/FactoryClassName:
VersionChanged: '2.0'
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryBot/FactoryClassName

RSpec/Rails:
Enabled: true
Include: *1
Language: *2

RSpec/Rails/AvoidSetupHook:
Description: Checks that tests use RSpec `before` hook over Rails `setup` method.
Enabled: pending
Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/rspec/config_formatter.rb
Expand Up @@ -7,6 +7,7 @@ module RSpec
# Builds a YAML config file from two config hashes
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/'

def initialize(config, descriptions)
Expand All @@ -24,6 +25,8 @@ def dump

def unified_config
cops.each_with_object(config.dup) do |cop, unified|
next if SUBDEPARTMENTS.include?(cop)
Copy link
Member

Choose a reason for hiding this comment

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

so those are not really cops, but departments declarations. Nice

Copy link
Member Author

Choose a reason for hiding this comment

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

Most of them are cops, but some are departments. It's because cops partially comes from config.keys. And we've included departments separately to config now.


unified[cop] = config.fetch(cop)
.merge(descriptions.fetch(cop))
.merge('StyleGuide' => STYLE_GUIDE_BASE_URL + cop.sub('RSpec/', ''))
Expand Down
2 changes: 1 addition & 1 deletion spec/project/default_config_spec.rb
Expand Up @@ -29,7 +29,7 @@
end

let(:config_keys) do
cop_names + %w[RSpec]
cop_names + %w[RSpec RSpec/Capybara RSpec/FactoryBot RSpec/Rails]
end

def cop_configuration(config_key)
Expand Down