class RuboCop::Cop::Style::RedundantConstantBase

end
::Const
module A
# good
end
::Const
class A
# good
end
Const
class << self
# good
end
::Const
class << self
# bad
Const
# good
::Const
# bad
@example
`Lint/ConstantResolution` cop which is disabled by default.
conflicting rules. Because it respects user configurations that want to enable
NOTE: This cop is disabled if ‘Lint/ConstantResolution` cop is enabled to prevent
avoid such meaningless `::` prefix to avoid confusion.
is empty, there is no need to prepend `::`, so it would be nice to consistently
understand from the code whether the `::` is intended or not. Where `Module.nesting`
How Ruby searches constant is a bit complicated, and it can often be difficult to
Avoid redundant `::` prefix on constant.

def bad?(node)

def bad?(node)
  module_nesting_ancestors_of(node).none?
end

def lint_constant_resolution_config

def lint_constant_resolution_config
  config.for_cop('Lint/ConstantResolution')
end

def lint_constant_resolution_cop_enabled?

def lint_constant_resolution_cop_enabled?
  lint_constant_resolution_config.fetch('Enabled', false)
end

def module_nesting_ancestors_of(node)

def module_nesting_ancestors_of(node)
  node.each_ancestor(:class, :module).reject do |ancestor|
    ancestor.class_type? && used_in_super_class_part?(node, class_node: ancestor)
  end
end

def on_cbase(node)

def on_cbase(node)
  return if lint_constant_resolution_cop_enabled?
  return unless bad?(node)
  add_offense(node) do |corrector|
    corrector.remove(node)
  end
end

def used_in_super_class_part?(node, class_node:)

def used_in_super_class_part?(node, class_node:)
  class_node.parent_class&.each_descendant(:cbase)&.any? do |descendant|
    descendant.equal?(node)
  end
end