Skip to content

Commit

Permalink
Merge pull request #10831 from koic/fix_an_error_when_using_changed_p…
Browse files Browse the repository at this point in the history
…arameters_by_external_library

Fix an error when using `changed_parameters` by external library
  • Loading branch information
koic committed Jul 25, 2022
2 parents 4537491 + dd9c99e commit 20990ed
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
@@ -0,0 +1 @@
* [#10831](https://github.com/rubocop/rubocop/pull/10831): Fix an error when using `changed_parameters` in obsoletion.yml by external library. ([@koic][])
9 changes: 7 additions & 2 deletions lib/rubocop/config_obsoletion.rb
Expand Up @@ -47,10 +47,15 @@ def reject_obsolete!

# Default rules for obsoletions are in config/obsoletion.yml
# Additional rules files can be added with `RuboCop::ConfigObsoletion.files << filename`
def load_rules
def load_rules # rubocop:disable Metrics/AbcSize
rules = self.class.files.each_with_object({}) do |filename, hash|
hash.merge!(YAML.safe_load(File.read(filename))) do |_key, first, second|
first.merge(second)
case first
when Hash
first.merge(second)
when Array
first.concat(second)
end
end
end

Expand Down
23 changes: 23 additions & 0 deletions spec/rubocop/config_obsoletion_spec.rb
Expand Up @@ -573,5 +573,28 @@
expect { config_obsoletion.reject_obsolete! }.not_to raise_error
end
end

context 'when using `changed_parameters` by an external library' do
after { described_class.files = [described_class::DEFAULT_RULES_FILE] }

let(:hash) { {} }
let(:external_obsoletions) do
create_file('external/obsoletions.yml', <<~YAML)
changed_parameters:
- cops: Rails/FindEach
parameters: IgnoredMethods
alternatives:
- AllowedMethods
- AllowedPatterns
severity: warning
YAML
end

it 'allows the extracted cops' do
described_class.files << external_obsoletions

expect { config_obsoletion.reject_obsolete! }.not_to raise_error
end
end
end
end

0 comments on commit 20990ed

Please sign in to comment.