Class: RuboCop::ConfigObsoletion Private
Overview
This class handles obsolete configuration.
Constant Summary
-
COP_RULE_CLASSES =
Internal use only
# File 'lib/rubocop/config_obsoletion.rb', line 8{ 'renamed' => RenamedCop, 'removed' => RemovedCop, 'split' => SplitCop, 'extracted' => ExtractedCop }.freeze
-
DEFAULT_RULES_FILE =
Internal use only
# File 'lib/rubocop/config_obsoletion.rb', line 7File.join(ConfigLoader::RUBOCOP_HOME, 'config', 'obsoletion.yml')
-
LOAD_RULES_CACHE =
private
Internal use only
# File 'lib/rubocop/config_obsoletion.rb', line 18{}
-
PARAMETER_RULE_CLASSES =
Internal use only
# File 'lib/rubocop/config_obsoletion.rb', line 14{ 'changed_parameters' => ChangedParameter, 'changed_enforced_styles' => ChangedEnforcedStyles }.freeze
Class Attribute Summary
- .files rw Internal use only Internal use only
Class Method Summary
- .legacy_cop_names Internal use only Internal use only
- .new(config) ⇒ ConfigObsoletion constructor Internal use only Internal use only
Instance Attribute Summary
Instance Method Summary
- #reject_obsolete! Internal use only Internal use only
-
#load_cop_rules(rules)
private
Internal use only
Internal use only
Cop rules are keyed by the name of the original cop.
-
#load_parameter_rules(rules)
private
Internal use only
Internal use only
Parameter rules may apply to multiple cops and multiple parameters and are given as an array.
-
#load_rules
private
Internal use only
Internal use only
Default rules for obsoletions are in config/obsoletion.yml Additional rules files can be added with
RuboCop::ConfigObsoletion.files << filename
. - #obsoletions private Internal use only Internal use only
Class Attribute Details
.files (rw)
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/config_obsoletion.rb', line 24
attr_accessor :files
Class Method Details
.legacy_cop_names
This method is for internal use only.
[ GitHub ]
Instance Attribute Details
#rules (readonly)
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/config_obsoletion.rb', line 21
attr_reader :rules, :warnings
#warnings (readonly)
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/config_obsoletion.rb', line 21
attr_reader :rules, :warnings
Instance Method Details
#load_cop_rules(rules) (private)
This method is for internal use only.
Cop rules are keyed by the name of the original cop
# File 'lib/rubocop/config_obsoletion.rb', line 72
def load_cop_rules(rules) rules.flat_map do |rule_type, data| data.filter_map do |cop_name, configuration| next unless configuration # allow configurations to be disabled with `CopName: ~` COP_RULE_CLASSES[rule_type].new(@config, cop_name, configuration) end end end
#load_parameter_rules(rules) (private)
This method is for internal use only.
Parameter rules may apply to multiple cops and multiple parameters and are given as an array. Each combination is turned into a separate rule object.
# File 'lib/rubocop/config_obsoletion.rb', line 85
def load_parameter_rules(rules) rules.flat_map do |rule_type, data| data.flat_map do |configuration| cops = Array(configuration['cops']) parameters = Array(configuration['parameters']) cops.product(parameters).map do |cop, parameter| PARAMETER_RULE_CLASSES[rule_type].new(@config, cop, parameter, configuration) end end end end
#load_rules (private)
This method is for internal use only.
Default rules for obsoletions are in config/obsoletion.yml
Additional rules files can be added with RuboCop::ConfigObsoletion.files << filename
# File 'lib/rubocop/config_obsoletion.rb', line 52
def load_rules # rubocop:disable Metrics/AbcSize 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 cop_rules = rules.slice(*COP_RULE_CLASSES.keys) parameter_rules = rules.slice(*PARAMETER_RULE_CLASSES.keys) load_cop_rules(cop_rules).concat(load_parameter_rules(parameter_rules)) end
#obsoletions (private)
This method is for internal use only.
[ GitHub ]
# File 'lib/rubocop/config_obsoletion.rb', line 98
def obsoletions rules.map do |rule| next unless rule.violated? if rule.warning? @warnings.push(rule. ) next end rule. end end
#reject_obsolete!
This method is for internal use only.
# File 'lib/rubocop/config_obsoletion.rb', line 41
def reject_obsolete! = obsoletions.flatten.compact return if .empty? raise ValidationError, .join("\n") end