Skip to content

Commit

Permalink
Merge pull request #18423 from Homebrew/caveats-strict
Browse files Browse the repository at this point in the history
caveats: `typed: strict`
  • Loading branch information
MikeMcQuaid authored Sep 26, 2024
2 parents f065334 + 55fab88 commit 9ce39ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions Library/Homebrew/caveats.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true

require "language/python"
Expand All @@ -8,12 +8,15 @@
class Caveats
extend Forwardable

sig { returns(Formula) }
attr_reader :formula

sig { params(formula: Formula).void }
def initialize(formula)
@formula = formula
end

sig { returns(String) }
def caveats
caveats = []
begin
Expand Down Expand Up @@ -46,6 +49,7 @@ def caveats

delegate [:empty?, :to_s] => :caveats

sig { params(skip_reason: T::Boolean).returns(T.nilable(String)) }
def keg_only_text(skip_reason: false)
return unless formula.keg_only?

Expand Down Expand Up @@ -99,16 +103,18 @@ def keg_only_text(skip_reason: false)

private

sig { returns(T.nilable(Keg)) }
def keg
@keg ||= [formula.prefix, formula.opt_prefix, formula.linked_keg].filter_map do |d|
@keg ||= T.let([formula.prefix, formula.opt_prefix, formula.linked_keg].filter_map do |d|
Keg.new(d.resolved_path)
rescue
nil
end.first
end.first, T.nilable(Keg))
end

sig { params(shell: Symbol).returns(T.nilable(String)) }
def function_completion_caveats(shell)
return unless keg
return unless (keg = self.keg)
return unless which(shell.to_s, ORIGINAL_PATHS)

completion_installed = keg.completion_installed?(shell)
Expand Down Expand Up @@ -140,9 +146,10 @@ def function_completion_caveats(shell)
end
end

sig { returns(T.nilable(String)) }
def elisp_caveats
return if formula.keg_only?
return unless keg
return unless (keg = self.keg)
return unless keg.elisp_installed?

<<~EOS
Expand All @@ -151,6 +158,7 @@ def elisp_caveats
EOS
end

sig { returns(T.nilable(String)) }
def service_caveats
return if !formula.service? && !Utils::Service.installed?(formula) && !keg&.plist_installed?
return if formula.service? && !formula.service.command? && !Utils::Service.installed?(formula)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def run
caveats = Caveats.new(formula)
opoo <<~EOS
Refusing to link macOS provided/shadowed software: #{keg.name}
#{caveats.keg_only_text(skip_reason: true).strip}
#{T.must(caveats.keg_only_text(skip_reason: true)).strip}
EOS
next
end
Expand Down

0 comments on commit 9ce39ee

Please sign in to comment.