Skip to content

Commit

Permalink
Optimize rspec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Nov 30, 2023
1 parent 4753e92 commit 7f0a589
Showing 1 changed file with 11 additions and 8 deletions.
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|
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

0 comments on commit 7f0a589

Please sign in to comment.