class RuboCop::Cop::InternalAffairs::CopEnabled


# good<br><br>cop_config && cop_config[‘Foo’]
cop_config = config.for_cop(‘Department/CopName’)
# bad
# when keeping a cop’s config in a local and then checking the ‘Enabled` key
@example
config.cop_enabled?(’Department/CopName’)
# good

config.for_cop(‘Department/CopName’)[‘Enabled’]
# bad
# ‘for_cop(…)[’Enabled’]
@example
traversing the config hash.
Use ‘config.cop_enabled?(’Department/CopName’)‘ instead of

def handle_for_cop(node, config_var, cop_name)

def handle_for_cop(node, config_var, cop_name)
  source = node.source
  quote = cop_name.loc.begin.source
  cop_name = cop_name.value
  replacement = "#{config_var.source}.cop_enabled?(#{quote}#{cop_name}#{quote})"
  message = format(MSG, source: source, replacement: replacement)
  add_offense(node, message: message) do |corrector|
    corrector.replace(node, replacement)
  end
end

def handle_hash(node, config_var)

def handle_hash(node, config_var)
  message = format(MSG_HASH, hash_name: config_var)
  add_offense(node, message: message)
end

def on_send(node)

def on_send(node)
  if (config_var, cop_name = for_cop_enabled?(node))
    handle_for_cop(node, config_var, cop_name)
  elsif (config_var = config_enabled_lookup?(node))
    return unless config_var.end_with?('_config')
    handle_hash(node, config_var)
  end
end