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 an error when using changed_parameters by external library #10831

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
@@ -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