Skip to content

Commit

Permalink
Merge pull request #16867 from Homebrew/stop-using-full-name-as-key-i…
Browse files Browse the repository at this point in the history
…n-cask-json-v3

cask: always return short cask tokens from core cask tap
  • Loading branch information
apainintheneck committed Mar 13, 2024
2 parents cdcf5d0 + ca5dfad commit 58b84c3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
14 changes: 8 additions & 6 deletions Library/Homebrew/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ def self.search_casks(string_or_regex)
end
end

cask_tokens = Tap.flat_map(&:cask_tokens).filter_map do |c|
next if c.start_with?("homebrew/cask/") && !Homebrew::EnvConfig.no_install_from_api?

c.sub(%r{^homebrew/cask.*/}, "")
end
cask_tokens |= Homebrew::API::Cask.all_casks.keys unless Homebrew::EnvConfig.no_install_from_api?
cask_tokens = Tap.each_with_object([]) do |tap, array|
# We can exclude the core cask tap because `CoreCaskTap#cask_tokens` returns short names by default.
if tap.official? && !tap.core_cask_tap?
tap.cask_tokens.each { |token| array << token.sub(%r{^homebrew/cask.*/}, "") }
else
tap.cask_tokens.each { |token| array << token }
end
end.uniq

results = search(cask_tokens, string_or_regex)
results += DidYouMean::SpellChecker.new(dictionary: cask_tokens)
Expand Down
12 changes: 6 additions & 6 deletions Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,12 @@ def self.ensure_installed!
instance.ensure_installed!
end

# @private
sig { params(file: Pathname).returns(String) }
def formula_file_to_name(file)
file.basename(".rb").to_s
end

# @private
sig { override.returns(T::Boolean) }
def should_report_analytics?
Expand Down Expand Up @@ -1245,12 +1251,6 @@ def synced_versions_formulae
end
end

# @private
sig { params(file: Pathname).returns(String) }
def formula_file_to_name(file)
file.basename(".rb").to_s
end

# @private
sig { params(file: Pathname).returns(String) }
def alias_file_to_name(file)
Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/tap_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ def initialize(tap, strict:)
Homebrew.with_no_api_env do
@name = tap.name
@path = tap.path
@cask_tokens = tap.cask_tokens
@tap_audit_exceptions = tap.audit_exceptions
@tap_style_exceptions = tap.style_exceptions
@tap_pypi_formula_mappings = tap.pypi_formula_mappings
@problems = []

@cask_tokens = tap.cask_tokens.map do |cask_token|
cask_token.split("/").last
end
@formula_aliases = tap.aliases.map do |formula_alias|
formula_alias.split("/").last
end
Expand Down Expand Up @@ -83,7 +85,7 @@ def check_formula_list(list_file, list)
invalid_formulae_casks = list.select do |formula_or_cask_name|
formula_names.exclude?(formula_or_cask_name) &&
formula_aliases.exclude?(formula_or_cask_name) &&
cask_tokens.exclude?("#{@name}/#{formula_or_cask_name}")
cask_tokens.exclude?(formula_or_cask_name)
end

return if invalid_formulae_casks.empty?
Expand Down

0 comments on commit 58b84c3

Please sign in to comment.