Merge pull request #19326 from gromgit/diagnostic/check-for-dups

diagnostics: add formula/cask dup check
This commit is contained in:
Mike McQuaid 2025-02-18 15:05:24 +00:00 committed by GitHub
commit ad93d5eb95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1040,6 +1040,40 @@ module Homebrew
end end
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 def all
methods.map(&:to_s).grep(/^check_/).sort methods.map(&:to_s).grep(/^check_/).sort
end end