Module: RuboCop::Cop::MethodPreference
- Included in:
- Style::CollectionMethods, Style::StringMethods
- Defined in:
- lib/rubocop/cop/mixin/method_preference.rb
Overview
Common code for cops that deal with preferred methods.
Instance Method Summary collapse
Instance Method Details
#default_cop_config ⇒ Object
24 25 26 |
# File 'lib/rubocop/cop/mixin/method_preference.rb', line 24 def default_cop_config ConfigLoader.default_configuration[cop_name] end |
#preferred_method(method) ⇒ Object
8 9 10 |
# File 'lib/rubocop/cop/mixin/method_preference.rb', line 8 def preferred_method(method) preferred_methods[method.to_sym] end |
#preferred_methods ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rubocop/cop/mixin/method_preference.rb', line 12 def preferred_methods @preferred_methods ||= begin # Make sure default configuration 'foo' => 'bar' is removed from # the total configuration if there is a 'bar' => 'foo' override. default = default_cop_config['PreferredMethods'] merged = cop_config['PreferredMethods'] overrides = merged.values - default.values merged.reject { |key, _| overrides.include?(key) }.symbolize_keys end end |