diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 64f7185255..fbf5714d57 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -1040,6 +1040,40 @@ module Homebrew end end + def non_core_taps + @non_core_taps ||= Tap.installed.reject(&:core_tap?).reject(&:core_cask_tap?) + end + + def check_for_duplicate_formulae + core_formula_names = CoreTap.instance.formula_names + shadowed_formula_full_names = non_core_taps.flat_map do |tap| + tap_formula_names = tap.formula_names.map { |s| s.delete_prefix("#{tap.name}/") } + (core_formula_names & tap_formula_names).map { |f| "#{tap.name}/#{f}" } + end.compact + return if shadowed_formula_full_names.empty? + + <<~EOS + The following formulae have the same name as core formulae: + #{shadowed_formula_full_names.join("\n ")} + You will need to use their full names throughout Homebrew. + EOS + end + + def check_for_duplicate_casks + core_cask_names = CoreCaskTap.instance.cask_tokens + shadowed_cask_full_names = non_core_taps.flat_map do |tap| + tap_cask_names = tap.cask_tokens.map { |s| s.delete_prefix("#{tap.name}/") } + (core_cask_names & tap_cask_names).map { |f| "#{tap.name}/#{f}" } + end.compact + return if shadowed_cask_full_names.empty? + + <<~EOS + The following casks have the same name as core casks: + #{shadowed_cask_full_names.join("\n ")} + You will need to use their full names throughout Homebrew. + EOS + end + def all methods.map(&:to_s).grep(/^check_/).sort end