Skip to content

Commit

Permalink
formula: allow excluding deprecate! reason when disable! exists
Browse files Browse the repository at this point in the history
  • Loading branch information
cho-m committed Oct 30, 2024
1 parent 0e24ee2 commit 5cb0d67
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 3 additions & 5 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4237,12 +4237,10 @@ def pour_bottle?(only_if: nil, &block)
# @see https://docs.brew.sh/Deprecating-Disabling-and-Removing-Formulae
# @see DeprecateDisable::FORMULA_DEPRECATE_DISABLE_REASONS
# @api public
def deprecate!(date:, because:)
def deprecate!(date:, because: nil)
@deprecation_date = Date.parse(date)
return if @deprecation_date > Date.today

@deprecation_reason = because
@deprecated = true
@deprecated = !disabled? && @deprecation_date <= Date.today
@deprecation_reason = @deprecated ? (because || @deprecation_reason) : nil
end

# Whether this {Formula} is deprecated (i.e. warns on installation).
Expand Down
5 changes: 3 additions & 2 deletions Library/Homebrew/rubocops/deprecate_disable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ class DeprecateDisableReason < FormulaCop
sig { override.params(formula_nodes: FormulaNodes).void }
def audit_formula(formula_nodes)
body_node = formula_nodes.body_node
any_reason_found = T.let(false, T::Boolean)

[:deprecate!, :disable!].each do |method|
[:disable!, :deprecate!].each do |method|
node = find_node_method_by_name(body_node, method)

next if node.nil?
Expand All @@ -72,7 +73,7 @@ def audit_formula(formula_nodes)
end
end

next if reason_found
next if any_reason_found ||= reason_found

case method
when :deprecate!
Expand Down
12 changes: 12 additions & 0 deletions Library/Homebrew/test/rubocops/deprecate_disable/reason_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,16 @@ class Foo < Formula
RUBY
end
end

context "when auditing `deprecate!` and `disable!`" do
it "reports no offense if `reason` exists on `deprecate!` but is absent on `disable!`" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
disable! date: "2021-08-28", because: :does_not_build
deprecate! date: "2020-08-28"
end
RUBY
end
end
end

0 comments on commit 5cb0d67

Please sign in to comment.