Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cask: always return short cask tokens from core cask tap #16867

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.*/}, "") }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it was there before, but what's the point of this sub?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that we want to only search by cask token for internal taps so that brew search version doesn't return all cask-versions casks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this is kinda begging for something like Formula#name vs. Formula#full_name

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 @@ -1059,6 +1059,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 @@ -1229,12 +1235,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 @@
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

Check warning on line 23 in Library/Homebrew/tap_auditor.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/tap_auditor.rb#L22-L23

Added lines #L22 - L23 were not covered by tests
end
@formula_aliases = tap.aliases.map do |formula_alias|
formula_alias.split("/").last
end
Expand Down Expand Up @@ -83,7 +85,7 @@
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