Skip to content

Commit 21f3536

Browse files
committed
deprecate_disable: typed: strict
1 parent d09fb09 commit 21f3536

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Library/Homebrew/cask/installer.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ def install
134134
raise
135135
end
136136

137+
sig { void }
137138
def check_deprecate_disable
138139
deprecate_disable_type = DeprecateDisable.type(@cask)
139140
return if deprecate_disable_type.nil?
140141

141-
message = DeprecateDisable.message(@cask)
142+
message = DeprecateDisable.message(@cask).to_s
142143
message_full = "#{@cask.token} has been #{message}"
143144

144145
case deprecate_disable_type

Library/Homebrew/deprecate_disable.rb

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# typed: true # rubocop:todo Sorbet/StrictSigil
1+
# typed: strict
22
# frozen_string_literal: true
33

44
# Helper module for handling `disable!` and `deprecate!`.
55
# @api internal
66
module DeprecateDisable
77
module_function
88

9-
FORMULA_DEPRECATE_DISABLE_REASONS = {
9+
FORMULA_DEPRECATE_DISABLE_REASONS = T.let({
1010
does_not_build: "does not build",
1111
no_license: "has no license",
1212
repo_archived: "has an archived upstream repository",
@@ -19,27 +19,29 @@ module DeprecateDisable
1919
"a different checksum than the current one. " \
2020
"Upstream's repository might have been compromised. " \
2121
"We can re-package this once upstream has confirmed that they retagged their release",
22-
}.freeze
22+
}.freeze, T::Hash[Symbol, String])
2323

24-
CASK_DEPRECATE_DISABLE_REASONS = {
24+
CASK_DEPRECATE_DISABLE_REASONS = T.let({
2525
discontinued: "is discontinued upstream",
2626
moved_to_mas: "is now exclusively distributed on the Mac App Store",
2727
no_longer_available: "is no longer available upstream",
2828
no_longer_meets_criteria: "no longer meets the criteria for acceptable casks",
2929
unmaintained: "is not maintained upstream",
3030
unsigned: "is unsigned or does not meet signature requirements",
31-
}.freeze
31+
}.freeze, T::Hash[Symbol, String])
3232

3333
# One year when << or >> to Date.today.
3434
REMOVE_DISABLED_TIME_WINDOW = 12
35-
REMOVE_DISABLED_BEFORE = (Date.today << REMOVE_DISABLED_TIME_WINDOW).freeze
35+
REMOVE_DISABLED_BEFORE = T.let((Date.today << REMOVE_DISABLED_TIME_WINDOW).freeze, Date)
3636

37+
sig { params(formula_or_cask: T.any(Formula, Cask::Cask)).returns(T.nilable(Symbol)) }
3738
def type(formula_or_cask)
3839
return :deprecated if formula_or_cask.deprecated?
3940

4041
:disabled if formula_or_cask.disabled?
4142
end
4243

44+
sig { params(formula_or_cask: T.any(Formula, Cask::Cask)).returns(T.nilable(String)) }
4345
def message(formula_or_cask)
4446
return if type(formula_or_cask).blank?
4547

@@ -92,9 +94,12 @@ def message(formula_or_cask)
9294
message
9395
end
9496

97+
sig { params(string: T.nilable(String), type: Symbol).returns(T.nilable(T.any(String, Symbol))) }
9598
def to_reason_string_or_symbol(string, type:)
96-
if (type == :formula && FORMULA_DEPRECATE_DISABLE_REASONS.key?(string&.to_sym)) ||
97-
(type == :cask && CASK_DEPRECATE_DISABLE_REASONS.key?(string&.to_sym))
99+
return if string.nil?
100+
101+
if (type == :formula && FORMULA_DEPRECATE_DISABLE_REASONS.key?(string.to_sym)) ||
102+
(type == :cask && CASK_DEPRECATE_DISABLE_REASONS.key?(string.to_sym))
98103
return string.to_sym
99104
end
100105

0 commit comments

Comments
 (0)