Skip to content

Commit 5cb0d67

Browse files
committed
formula: allow excluding deprecate! reason when disable! exists
1 parent 0e24ee2 commit 5cb0d67

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

Library/Homebrew/formula.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4237,12 +4237,10 @@ def pour_bottle?(only_if: nil, &block)
42374237
# @see https://docs.brew.sh/Deprecating-Disabling-and-Removing-Formulae
42384238
# @see DeprecateDisable::FORMULA_DEPRECATE_DISABLE_REASONS
42394239
# @api public
4240-
def deprecate!(date:, because:)
4240+
def deprecate!(date:, because: nil)
42414241
@deprecation_date = Date.parse(date)
4242-
return if @deprecation_date > Date.today
4243-
4244-
@deprecation_reason = because
4245-
@deprecated = true
4242+
@deprecated = !disabled? && @deprecation_date <= Date.today
4243+
@deprecation_reason = @deprecated ? (because || @deprecation_reason) : nil
42464244
end
42474245

42484246
# Whether this {Formula} is deprecated (i.e. warns on installation).

Library/Homebrew/rubocops/deprecate_disable.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ class DeprecateDisableReason < FormulaCop
4545
sig { override.params(formula_nodes: FormulaNodes).void }
4646
def audit_formula(formula_nodes)
4747
body_node = formula_nodes.body_node
48+
any_reason_found = T.let(false, T::Boolean)
4849

49-
[:deprecate!, :disable!].each do |method|
50+
[:disable!, :deprecate!].each do |method|
5051
node = find_node_method_by_name(body_node, method)
5152

5253
next if node.nil?
@@ -72,7 +73,7 @@ def audit_formula(formula_nodes)
7273
end
7374
end
7475

75-
next if reason_found
76+
next if any_reason_found ||= reason_found
7677

7778
case method
7879
when :deprecate!

Library/Homebrew/test/rubocops/deprecate_disable/reason_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,16 @@ class Foo < Formula
324324
RUBY
325325
end
326326
end
327+
328+
context "when auditing `deprecate!` and `disable!`" do
329+
it "reports no offense if `reason` exists on `deprecate!` but is absent on `disable!`" do
330+
expect_no_offenses(<<~RUBY)
331+
class Foo < Formula
332+
url 'https://brew.sh/foo-1.0.tgz'
333+
disable! date: "2021-08-28", because: :does_not_build
334+
deprecate! date: "2020-08-28"
335+
end
336+
RUBY
337+
end
338+
end
327339
end

0 commit comments

Comments
 (0)