Skip to content

Commit

Permalink
Manually resolve Style/SafeNavigationChainLength violations
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Nov 2, 2024
1 parent f23dd0d commit 9203419
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def uninstall_flight_blocks?
sig { returns(T.nilable(Time)) }
def install_time
# <caskroom_path>/.metadata/<version>/<timestamp>/Casks/<token>.{rb,json} -> <timestamp>
time = installed_caskfile&.dirname&.dirname&.basename&.to_s
Time.strptime(time, Metadata::TIMESTAMP_FORMAT) if time
caskfile = installed_caskfile

Check warning on line 176 in Library/Homebrew/cask/cask.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/cask.rb#L176

Added line #L176 was not covered by tests
caskfile ? Time.strptime(caskfile.dirname.dirname.basename.to_s, Metadata::TIMESTAMP_FORMAT) : nil
end

sig { returns(T.nilable(Pathname)) }
Expand Down
5 changes: 3 additions & 2 deletions Library/Homebrew/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ def stale_formula?(pathname, scrub)

resource_name = basename_str[/\A.*?--(.*?)--?(?:#{Regexp.escape(version.to_s)})/, 1]

stable = formula.stable
if resource_name == "patch"
patch_hashes = formula.stable&.patches&.select(&:external?)&.map(&:resource)&.map(&:version)
patch_hashes = stable&.patches&.filter_map { _1.resource.version if _1.external }
return true unless patch_hashes&.include?(Checksum.new(version.to_s))
elsif resource_name && (resource_version = formula.stable&.resources&.dig(resource_name)&.version)
elsif resource_name && stable && (resource_version = stable.resources[resource_name]&.version)
return true if resource_version != version
elsif (formula.latest_version_installed? && formula.pkg_version.to_s != version) ||
formula.pkg_version.to_s > version
Expand Down
6 changes: 5 additions & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,11 @@ def oldnames
# @api internal
sig { returns(T::Array[String]) }
def aliases
@aliases ||= tap&.alias_reverse_table&.dig(full_name)&.map { _1.split("/").last } || []
@aliases ||= if (tap = self.tap)
tap.alias_reverse_table.fetch(full_name, []).map { _1.split("/").last }
else
[]
end
end

# The {Resource}s for the currently active {SoftwareSpec}.
Expand Down
10 changes: 6 additions & 4 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,12 @@ def post_install_defined?

@caveats_string = json_formula["caveats"]
def caveats
self.class.instance_variable_get(:@caveats_string)
&.gsub(HOMEBREW_PREFIX_PLACEHOLDER, HOMEBREW_PREFIX)
&.gsub(HOMEBREW_CELLAR_PLACEHOLDER, HOMEBREW_CELLAR)
&.gsub(HOMEBREW_HOME_PLACEHOLDER, Dir.home)
caveats_string = self.class.instance_variable_get(:@caveats_string)
return unless caveats_string

caveats_string.gsub(HOMEBREW_PREFIX_PLACEHOLDER, HOMEBREW_PREFIX)
.gsub(HOMEBREW_CELLAR_PLACEHOLDER, HOMEBREW_CELLAR)
.gsub(HOMEBREW_HOME_PLACEHOLDER, Dir.home)
end

@tap_git_head_string = if Homebrew::API.internal_json_v3?
Expand Down
11 changes: 7 additions & 4 deletions Library/Homebrew/livecheck/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,13 @@ def self.run_checks(
extract_plist = true if formulae_and_casks_total == 1

formulae_checked = formulae_and_casks_to_check.map.with_index do |formula_or_cask, i|
formula = formula_or_cask if formula_or_cask.is_a?(Formula)
cask = formula_or_cask if formula_or_cask.is_a?(Cask::Cask)
case formula_or_cask
when Formula
formula = formula_or_cask
formula.head&.downloader&.quiet!
when Cask::Cask
cask = formula_or_cask
end

use_full_name = full_name || ambiguous_names.include?(formula_or_cask)
name = package_or_resource_name(formula_or_cask, full_name: use_full_name)
Expand Down Expand Up @@ -238,8 +243,6 @@ def self.run_checks(
next
end

formula&.head&.downloader&.quiet!

# Use the `stable` version for comparison except for installed
# head-only formulae. A formula with `stable` and `head` that's
# installed using `--head` will still use the `stable` version for
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def install(quiet: false, clone_target: nil,
Commands.rebuild_commands_completion_list
link_completions_and_manpages

formatted_contents = contents.presence&.to_sentence&.dup&.prepend(" ")
formatted_contents = contents.presence&.to_sentence&.prepend(" ")
$stderr.puts "Tapped#{formatted_contents} (#{path.abv})." unless quiet

require "description_cache_store"
Expand Down Expand Up @@ -622,7 +622,7 @@ def uninstall(manual: false)
$stderr.puts "Untapping #{name}..."

abv = path.abv
formatted_contents = contents.presence&.to_sentence&.dup&.prepend(" ")
formatted_contents = contents.presence&.to_sentence&.prepend(" ")

require "description_cache_store"
CacheStoreDatabase.use(:descriptions) do |db|
Expand Down
4 changes: 3 additions & 1 deletion Library/Homebrew/utils/spdx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ def string_to_license_expression(string)
if with_parts.length > 1
{ with_parts.first => { with: with_parts.second } }
else
license_sym = result[/^#{LICENSEREF_PREFIX}(.+)/o, 1]&.downcase&.tr("-", "_")&.to_sym
return result unless result.start_with?(LICENSEREF_PREFIX)

license_sym = result.delete_prefix(LICENSEREF_PREFIX).downcase.tr("-", "_").to_sym
ALLOWED_LICENSE_SYMBOLS.include?(license_sym) ? license_sym : result
end
end
Expand Down

0 comments on commit 9203419

Please sign in to comment.