Class: RuboCop::ConfigObsoletion Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/config_obsoletion.rb,
lib/rubocop/config_obsoletion/rule.rb,
lib/rubocop/config_obsoletion/cop_rule.rb,
lib/rubocop/config_obsoletion/split_cop.rb,
lib/rubocop/config_obsoletion/removed_cop.rb,
lib/rubocop/config_obsoletion/renamed_cop.rb,
lib/rubocop/config_obsoletion/extracted_cop.rb,
lib/rubocop/config_obsoletion/parameter_rule.rb,
lib/rubocop/config_obsoletion/changed_parameter.rb,
lib/rubocop/config_obsoletion/changed_enforced_styles.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class handles obsolete configuration.

Defined Under Namespace

Classes: ChangedEnforcedStyles, ChangedParameter, CopRule, ExtractedCop, ParameterRule, RemovedCop, RenamedCop, Rule, SplitCop

Constant Summary collapse

DEFAULT_RULES_FILE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

File.join(ConfigLoader::RUBOCOP_HOME, 'config', 'obsoletion.yml')
COP_RULE_CLASSES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'renamed' => RenamedCop,
  'removed' => RemovedCop,
  'split' => SplitCop,
  'extracted' => ExtractedCop
}.freeze
PARAMETER_RULE_CLASSES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'changed_parameters' => ChangedParameter,
  'changed_enforced_styles' => ChangedEnforcedStyles
}.freeze

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ConfigObsoletion

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ConfigObsoletion.



66
67
68
69
70
# File 'lib/rubocop/config_obsoletion.rb', line 66

def initialize(config)
  @config = config
  @rules = load_rules
  @warnings = []
end

Class Attribute Details

.filesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/rubocop/config_obsoletion.rb', line 24

def files
  @files
end

Instance Attribute Details

#rulesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
# File 'lib/rubocop/config_obsoletion.rb', line 21

def rules
  @rules
end

#warningsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
# File 'lib/rubocop/config_obsoletion.rb', line 21

def warnings
  @warnings
end

Class Method Details

.deprecated_cop_name?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


45
46
47
# File 'lib/rubocop/config_obsoletion.rb', line 45

def deprecated_cop_name?(name)
  global.deprecated_cop_name?(name)
end

.deprecated_names_for(cop) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rubocop/config_obsoletion.rb', line 49

def deprecated_names_for(cop)
  @deprecated_names ||= {}
  return @deprecated_names[cop] if @deprecated_names.key?(cop)

  @deprecated_names[cop] = global.rules.filter_map do |rule|
    next unless rule.cop_rule?
    next unless rule.respond_to?(:new_name)
    next unless rule.new_name == cop

    rule.old_name
  end
end

.globalObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/rubocop/config_obsoletion.rb', line 26

def global
  @global ||= new(Config.new)
end

.legacy_cop_namesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
43
# File 'lib/rubocop/config_obsoletion.rb', line 40

def legacy_cop_names
  # Used by DepartmentName#qualified_legacy_cop_name
  global.legacy_cop_names
end

.reset!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
33
34
# File 'lib/rubocop/config_obsoletion.rb', line 30

def reset!
  @global = nil
  @deprecated_names = {}
  LOAD_RULES_CACHE[rules_cache_key] = nil
end

.rules_cache_keyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
# File 'lib/rubocop/config_obsoletion.rb', line 36

def rules_cache_key
  files.hash
end

Instance Method Details

#deprecated_cop_name?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


84
85
86
# File 'lib/rubocop/config_obsoletion.rb', line 84

def deprecated_cop_name?(name)
  legacy_cop_names.include?(name)
end

#legacy_cop_namesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
82
# File 'lib/rubocop/config_obsoletion.rb', line 79

def legacy_cop_names
  # Used by DepartmentName#qualified_legacy_cop_name
  cop_rules.map(&:old_name)
end

#reject_obsolete!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:



72
73
74
75
76
77
# File 'lib/rubocop/config_obsoletion.rb', line 72

def reject_obsolete!
  messages = obsoletions.flatten.compact
  return if messages.empty?

  raise ValidationError, messages.join("\n")
end