-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
RSpec/Language
isn't merging properly
#1126
Comments
I was under the impression that the default merging strategy for arrays in RuboCop configuration is
Following the advice from https://docs.rubocop.org/rubocop/1.0/configuration.html#merging-arrays-using-inherit_mode, I've tried:
RSpec:
inherit_mode:
merge:
- Language/Includes/Examples
- Language/Includes/Context and RSpec:
Language:
inherit_mode:
merge:
- Includes/Examples
- Includes/Context and RSpec:
Language:
Includes:
inherit_mode:
merge:
- Examples
- Context and none of this worked.
require:
- rubocop-rspec
RSpec:
Language:
Includes:
inherit_mode:
merge:
- Examples
Examples:
- endpoint
Helpers:
- set and still Adding inherit_gem:
rubocop-rspec: config/default.yml makes no difference. Symptom: > RuboCop::RSpec::Language.config
=> {"inherit_mode"=>{"merge"=>["Includes/Examples", "Includes/Context"]},
"ExampleGroups"=>
{"Regular"=>["describe", "context", "feature", "example_group"],
"Skipped"=>["xdescribe", "xcontext", "xfeature"],
"Focused"=>["fdescribe", "fcontext", "ffeature"]},
"Examples"=>
{"Regular"=>["it", "specify", "example", "scenario", "its"],
"Focused"=>["fit", "fspecify", "fexample", "fscenario", "focus"],
"Skipped"=>["xit", "xspecify", "xexample", "xscenario", "skip"],
"Pending"=>["pending"]},
"Expectations"=>["expect", "is_expected", "expect_any_instance_of"],
"Helpers"=>["set"],
"Hooks"=> ["prepend_before", "before", "append_before", "around", "prepend_after", "after", "append_after"],
"HookScopes"=>["each", "example", "context", "all", "suite"],
"Includes"=>
{"inherit_mode"=>{"merge"=>["Examples"]},
"Examples"=>["endpoint"],
"Context"=>["include_context"]},
"Runners"=>["to", "to_not", "not_to"],
"SharedGroups"=>
{"Examples"=>["shared_examples", "shared_examples_for"],
"Context"=>["shared_context"]},
"Subjects"=>["subject", "subject!"]} The # Set the config for dynamic DSL configuration-aware helpers
# that have no other means of accessing the configuration.
def on_new_investigation
super
RuboCop::RSpec::Language.config = config['RSpec']['Language']
end From RuboCop's standpoint, what is wrong? Why aren't those arrays merged? |
Ok I was hoping that there was something specific to language config loading happening in rubocop-rspec, but yeah it looks like we have some stuff to fix in rubocop. There are a couple tangentially related rubocop issues (eg. rubocop/rubocop#9325). I think it’s probably that merge_mode is overly complex and doesn’t cover edge cases properly. We should take this issue to the rubocop repo but I don’t have access to transfer it from here 😅 |
Can't remember the exact methodology I used to test how config merging works when the language configuration feature was about to be merged. To my shame, it was probably the optimistic "yay, no offences" approach, including the testing done a bit later in palkan/action_policy#138 and sibling PRs. I don't have permissions to transfer the issue over either. However, even though are some deficiencies on the RuboCop side, I believe we still have to address an issue with the missing |
Cry for help! Asking for help with configuring @bquorning @Darhazer |
It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn't work as intended anyway #1126 - if users would re-define RSpec DSL, they would have to do it for all sub-departments, as YAML defaults are only for the default config - if users would re-define RSpec DSL and use YAML defaults, too, the merging of the resulting config is undetermined Still, I believe having `Include` to work correctly is the most important. fixes #1160
It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn't work as intended anyway #1126 - if users would re-define RSpec DSL, they would have to do it for all sub-departments, as YAML defaults are only for the default config - if users would re-define RSpec DSL and use YAML defaults, too, the merging of the resulting config is undetermined Still, I believe having `Include` to work correctly is the most important. fixes #1160
It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn't work as intended anyway #1126 - if users would re-define RSpec DSL, they would have to do it for all sub-departments, as YAML defaults are only for the default config - if users would re-define RSpec DSL and use YAML defaults, too, the merging of the resulting config is undetermined Still, I believe having `Include` to work correctly is the most important. fixes #1160
It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn't work as intended anyway #1126 - if users would re-define RSpec DSL, they would have to do it for all sub-departments, as YAML defaults are only for the default config - if users would re-define RSpec DSL and use YAML defaults, too, the merging of the resulting config is undetermined Still, I believe having `Include` to work correctly is the most important. fixes #1160
Culpritrubocop/rubocop@52d03b4#diff-a923ce94f1d49facbed6a8bad517fe80d9052d653a1210c51530d39de572dcc1R131:
Debugbinding.pry if key == "Regular" Introspect: opts # => {:inherit_mode=>{}, :unset_nil=>true}
key # => "Regular"
base_hash # => {"inherit_mode"=>{"merge"=>["Regular"]}, "Regular"=>["it", "specify", "example", "scenario", "its"]}
derived_hash # => => {"Regular"=>["mycustomexamplealias"]}
RSpec:
Language:
Examples:
inherit_mode:
merge:
- Regular
Regular:
- it
- specify
- example
- scenario
- its
require:
- rubocop-rspec
RSpec:
Language:
Examples:
Regular:
- mycustomexamplealias Fix(es)Respect setting-local
|
See rubocop/rubocop-rspec#1126 `config/default.yml`: ```yaml RSpec: Language: Examples: inherit_mode: merge: - Regular Regular: - it - specify - example - scenario - its ``` `.rubocop.yml`: ```yaml require: - rubocop-rspec RSpec: Language: Examples: Regular: - mycustomexamplealias ``` Previously, locally-set `inherit_mode` in extension default configuration was not respected.
See rubocop/rubocop-rspec#1126 `config/default.yml`: ```yaml RSpec: Language: Examples: inherit_mode: merge: - Regular Regular: - it - specify - example - scenario - its ``` `.rubocop.yml`: ```yaml require: - rubocop-rspec RSpec: Language: Examples: Regular: - mycustomexamplealias ``` Previously, locally-set `inherit_mode` in extension default configuration was not respected.
I intend to bump the minimum required version of |
fixes #1126 Related fix in RuboCop rubocop/rubocop#9952
fixes #1126 Related fix in RuboCop rubocop/rubocop#9952
fixes #1126 See palkan/action_policy#103 (comment) If a third-party gem, e.g. `action_policy`, defines their `config/default.yml` and supplements to the default RSpec DSL that we provide in our `config/default.yml`, `rubocop`'s behaviour is to actually override the configuration, as `inherit_mode` is `override` for lists by default. RuboCop has recently [fixed the problem with ignored `inherit_mode`](rubocop/rubocop#9952) and we've [bumped to use `rubocop` version that includes the fix](#1181), but we haven't adjusted our `config/default.yml` to merge by default. This is causing both user project RSpec DSL configuration and third-party gem RSpec DSL configuration to override our default, rendering our cops blind. ### Example A new project ```ruby # Gemfile source 'https://rubygems.org' gem 'action_policy' gem 'rubocop-rspec' ``` ```yml # .rubocop.yml require: - rubocop-rspec inherit_gem: action_policy: config/rubocop-rspec.yml ``` ```ruby # spec/a_spec.rb RSpec.describe 'A' do it_behaves_like 'a' it_behaves_like 'a' describe_rule :show? do succeed 'when post is published' succeed 'when post is published' end end ``` Ideally, both the duplicated `it_behaves_like` and `succeed` should be detected. However, `action_policy`'s `Includes/Examples` setting overrides ours, and `it_behaves_like` disappears from this list. As a result, `rubocop` only detects the duplication of `succeed`, but not of `it_behaves_like`.
fixes #1126 See palkan/action_policy#103 (comment) If a third-party gem, e.g. `action_policy`, defines their `config/default.yml` and supplements to the default RSpec DSL that we provide in our `config/default.yml`, `rubocop`'s behaviour is to actually override the configuration, as `inherit_mode` is `override` for lists by default. RuboCop has recently [fixed the problem with ignored `inherit_mode`](rubocop/rubocop#9952) and we've [bumped to use `rubocop` version that includes the fix](#1181), but we haven't adjusted our `config/default.yml` to merge by default. This is causing both user project RSpec DSL configuration and third-party gem RSpec DSL configuration to override our default, rendering our cops blind. ### Example A new project ```ruby # Gemfile source 'https://rubygems.org' gem 'action_policy' gem 'rubocop-rspec' ``` ```yml # .rubocop.yml require: - rubocop-rspec inherit_gem: action_policy: config/rubocop-rspec.yml ``` ```ruby # spec/a_spec.rb RSpec.describe 'A' do it_behaves_like 'a' it_behaves_like 'a' describe_rule :show? do succeed 'when post is published' succeed 'when post is published' end end ``` Ideally, both the duplicated `it_behaves_like` and `succeed` should be detected. However, `action_policy`'s `Includes/Examples` setting overrides ours, and `it_behaves_like` disappears from this list. As a result, `rubocop` only detects the duplication of `succeed`, but not of `it_behaves_like`.
fixes #1126 See palkan/action_policy#103 (comment) If a third-party gem, e.g. `action_policy`, defines their `config/default.yml` and supplements to the default RSpec DSL that we provide in our `config/default.yml`, `rubocop`'s behaviour is to actually override the configuration, as `inherit_mode` is `override` for lists by default. RuboCop has recently [fixed the problem with ignored `inherit_mode`](rubocop/rubocop#9952) and we've [bumped to use `rubocop` version that includes the fix](#1181), but we haven't adjusted our `config/default.yml` to merge by default. This is causing both user project RSpec DSL configuration and third-party gem RSpec DSL configuration to override our default, rendering our cops blind. ### Example A new project ```ruby # Gemfile source 'https://rubygems.org' gem 'action_policy' gem 'rubocop-rspec' ``` ```yml # .rubocop.yml require: - rubocop-rspec inherit_gem: action_policy: config/rubocop-rspec.yml ``` ```ruby # spec/a_spec.rb RSpec.describe 'A' do it_behaves_like 'a' it_behaves_like 'a' describe_rule :show? do succeed 'when post is published' succeed 'when post is published' end end ``` Ideally, both the duplicated `it_behaves_like` and `succeed` should be detected. However, `action_policy`'s `Includes/Examples` setting overrides ours, and `it_behaves_like` disappears from this list. As a result, `rubocop` only detects the duplication of `succeed`, but not of `it_behaves_like`.
It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn't work as intended anyway #1126 - if users would re-define RSpec DSL, they would have to do it for all sub-departments, as YAML defaults are only for the default config - if users would re-define RSpec DSL and use YAML defaults, too, the merging of the resulting config is undetermined Still, I believe having `Include` to work correctly is the most important. fixes #1160
It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn't work as intended anyway #1126 - if users would re-define RSpec DSL, they would have to do it for all sub-departments, as YAML defaults are only for the default config - if users would re-define RSpec DSL and use YAML defaults, too, the merging of the resulting config is undetermined Still, I believe having `Include` to work correctly is the most important. fixes #1160
It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn't work as intended anyway #1126 - if users would re-define RSpec DSL, they would have to do it for all sub-departments, as YAML defaults are only for the default config - if users would re-define RSpec DSL and use YAML defaults, too, the merging of the resulting config is undetermined Still, I believe having `Include` to work correctly is the most important. fixes #1160
It turns out that the default config does not apply for sub-departments. It is weird on many levels: - RSpec DSL configuration didn't work - - RSpec DSL doesn't work as intended anyway #1126 - if users would re-define RSpec DSL, they would have to do it for all sub-departments, as YAML defaults are only for the default config - if users would re-define RSpec DSL and use YAML defaults, too, the merging of the resulting config is undetermined Still, I believe having `Include` to work correctly is the most important. fixes #1160
It appears that if values for
RSpec/Language
are being set in.rubocop.yml
, they are clobbering the existing setup and this is causing quite a few other cops to fail due to RSpec syntax not being recognized.With this minimal .rubocop.yml:
I get the following in
RuboCop::RSpec::Language.config
:You'll see that
ExampleGroups/Regular
andHelpers
have been overridden to only be the values I specified. Am I missing something?The text was updated successfully, but these errors were encountered: