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

Optimize rspec tests #12422

Merged
merged 1 commit into from
Dec 1, 2023
Merged
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
19 changes: 11 additions & 8 deletions lib/rubocop/config_obsoletion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ConfigObsoletion
'changed_parameters' => ChangedParameter,
'changed_enforced_styles' => ChangedEnforcedStyles
}.freeze
LOAD_RULES_CACHE = {} # rubocop:disable Style/MutableConstant
private_constant :LOAD_RULES_CACHE

attr_reader :rules, :warnings

Expand Down Expand Up @@ -48,16 +50,17 @@ 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 # 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|
case first
when Hash
first.merge(second)
when Array
first.concat(second)
rules = LOAD_RULES_CACHE[self.class.files] ||=
self.class.files.each_with_object({}) do |filename, hash|
hash.merge!(YAML.safe_load(File.read(filename))) do |_key, first, second|
koic marked this conversation as resolved.
Show resolved Hide resolved
case first
when Hash
first.merge(second)
when Array
first.concat(second)
end
end
end
end

cop_rules = rules.slice(*COP_RULE_CLASSES.keys)
parameter_rules = rules.slice(*PARAMETER_RULE_CLASSES.keys)
Expand Down