module Tapioca::RBIFilesHelper

def has_duplicated_scopes?(all_nodes, shims_or_todos)

: (Array[RBI::Node], Array[RBI::Node]) -> bool
def has_duplicated_scopes?(all_nodes, shims_or_todos)
  shims_or_todos_scopes = shims_or_todos.grep(RBI::Scope)
  return false if shims_or_todos_scopes.empty?
  # Extract the empty scopes from the shims or todos
  # We do not care about non-empty scopes because they hold definitions that we will check against Tapioca's
  # generated RBI files in another iteration.
  shims_or_todos_empty_scopes = shims_or_todos_scopes.select(&:empty?)
  # Extract the nodes that are not shims or todos (basically the nodes from the RBI files generated by Tapioca)
  not_shims_or_todos = all_nodes - shims_or_todos
  shims_or_todos_empty_scopes.any? do |scope|
    # Empty modules are always duplicates
    break true unless scope.is_a?(RBI::Class)
    # Empty classes without parents are also duplicates
    parent_name = scope.superclass_name
    break true unless parent_name
    # Empty classes that are not redefining the parent are also duplicates
    break true if not_shims_or_todos.any? do |node|
      node.is_a?(RBI::Class) && node.superclass_name == parent_name
    end
  end
end