deprecate!, disable!: allow symbols for reason
This commit is contained in:
parent
842335d47b
commit
4d0a1ff775
@ -1151,7 +1151,7 @@ class Formula
|
|||||||
# The reason this {Formula} is deprecated.
|
# The reason this {Formula} is deprecated.
|
||||||
# Returns `nil` if no reason is specified or the formula is not deprecated.
|
# Returns `nil` if no reason is specified or the formula is not deprecated.
|
||||||
# @method deprecation_reason
|
# @method deprecation_reason
|
||||||
# @return [String]
|
# @return [String, Symbol]
|
||||||
delegate deprecation_reason: :"self.class"
|
delegate deprecation_reason: :"self.class"
|
||||||
|
|
||||||
# Whether this {Formula} is disabled (i.e. cannot be installed).
|
# Whether this {Formula} is disabled (i.e. cannot be installed).
|
||||||
@ -1163,7 +1163,7 @@ class Formula
|
|||||||
# The reason this {Formula} is disabled.
|
# The reason this {Formula} is disabled.
|
||||||
# Returns `nil` if no reason is specified or the formula is not disabled.
|
# Returns `nil` if no reason is specified or the formula is not disabled.
|
||||||
# @method disable_reason
|
# @method disable_reason
|
||||||
# @return [String]
|
# @return [String, Symbol]
|
||||||
delegate disable_reason: :"self.class"
|
delegate disable_reason: :"self.class"
|
||||||
|
|
||||||
def skip_cxxstdlib_check?
|
def skip_cxxstdlib_check?
|
||||||
@ -2778,7 +2778,8 @@ class Formula
|
|||||||
# Deprecates a {Formula} (on a given date, if provided) so a warning is
|
# Deprecates a {Formula} (on a given date, if provided) so a warning is
|
||||||
# shown on each installation. If the date has not yet passed the formula
|
# shown on each installation. If the date has not yet passed the formula
|
||||||
# will not be deprecated.
|
# will not be deprecated.
|
||||||
# <pre>deprecate! date: "2020-08-27", because: "it is no longer maintained"</pre>
|
# <pre>deprecate! date: "2020-08-27", because: :unmaintained</pre>
|
||||||
|
# <pre>deprecate! date: "2020-08-27", because: "it has been replaced by"</pre>
|
||||||
def deprecate!(date: nil, because: nil)
|
def deprecate!(date: nil, because: nil)
|
||||||
# TODO: enable for next major/minor release
|
# TODO: enable for next major/minor release
|
||||||
# odeprecated "`deprecate!` without a reason", "`deprecate! because: \"reason\"`" if because.blank?
|
# odeprecated "`deprecate!` without a reason", "`deprecate! because: \"reason\"`" if because.blank?
|
||||||
@ -2798,13 +2799,14 @@ class Formula
|
|||||||
|
|
||||||
# The reason for deprecation of a {Formula}.
|
# The reason for deprecation of a {Formula}.
|
||||||
# Returns `nil` if no reason was provided or the formula is not deprecated.
|
# Returns `nil` if no reason was provided or the formula is not deprecated.
|
||||||
# @return [String]
|
# @return [String, Symbol]
|
||||||
attr_reader :deprecation_reason
|
attr_reader :deprecation_reason
|
||||||
|
|
||||||
# Disables a {Formula} (on a given date, if provided) so it cannot be
|
# Disables a {Formula} (on a given date, if provided) so it cannot be
|
||||||
# installed. If the date has not yet passed the formula
|
# installed. If the date has not yet passed the formula
|
||||||
# will be deprecated instead of disabled.
|
# will be deprecated instead of disabled.
|
||||||
# <pre>disable! date: "2020-08-27", because: "it no longer builds"</pre>
|
# <pre>disable! date: "2020-08-27", because: :does_not_build</pre>
|
||||||
|
# <pre>disable! date: "2020-08-27", because: "has been replaced by foo"</pre>
|
||||||
def disable!(date: nil, because: nil)
|
def disable!(date: nil, because: nil)
|
||||||
# TODO: enable for next major/minor release
|
# TODO: enable for next major/minor release
|
||||||
# odeprecated "`disable!` without a reason", "`disable! because: \"reason\"`" if because.blank?
|
# odeprecated "`disable!` without a reason", "`disable! because: \"reason\"`" if because.blank?
|
||||||
@ -2828,7 +2830,7 @@ class Formula
|
|||||||
|
|
||||||
# The reason for a {Formula} is disabled.
|
# The reason for a {Formula} is disabled.
|
||||||
# Returns `nil` if no reason was provided or the formula is not disabled.
|
# Returns `nil` if no reason was provided or the formula is not disabled.
|
||||||
# @return [String]
|
# @return [String, Symbol]
|
||||||
attr_reader :disable_reason
|
attr_reader :disable_reason
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
|
|||||||
@ -202,15 +202,38 @@ class FormulaInstaller
|
|||||||
def check_install_sanity
|
def check_install_sanity
|
||||||
raise FormulaInstallationAlreadyAttemptedError, formula if self.class.attempted.include?(formula)
|
raise FormulaInstallationAlreadyAttemptedError, formula if self.class.attempted.include?(formula)
|
||||||
|
|
||||||
|
deprecate_disable_reasons = {
|
||||||
|
does_not_build: "does not build",
|
||||||
|
no_license: "has no license",
|
||||||
|
repo_archived: "has an archived upstream repository",
|
||||||
|
repo_removed: "has a removed upstream repository",
|
||||||
|
unmaintained: "is not maintained upstream",
|
||||||
|
unsupported: "is not supported upstream",
|
||||||
|
deprecated_upstream: "is deprecated upstream",
|
||||||
|
versioned_formula: "is a versioned formula",
|
||||||
|
}
|
||||||
|
|
||||||
if formula.deprecated?
|
if formula.deprecated?
|
||||||
if formula.deprecation_reason.present?
|
if formula.deprecation_reason.present?
|
||||||
opoo "#{formula.full_name} has been deprecated because #{formula.deprecation_reason}!"
|
reason = if deprecate_disable_reasons.key? formula.deprecation_reason
|
||||||
|
deprecate_disable_reasons[formula.deprecation_reason]
|
||||||
|
else
|
||||||
|
deprecate_disable_reasons
|
||||||
|
end
|
||||||
|
|
||||||
|
opoo "#{formula.full_name} has been deprecated because it #{reason}!"
|
||||||
else
|
else
|
||||||
opoo "#{formula.full_name} has been deprecated!"
|
opoo "#{formula.full_name} has been deprecated!"
|
||||||
end
|
end
|
||||||
elsif formula.disabled?
|
elsif formula.disabled?
|
||||||
if formula.disable_reason.present?
|
if formula.disable_reason.present?
|
||||||
odie "#{formula.full_name} has been disabled because #{formula.disable_reason}!"
|
reason = if deprecate_disable_reasons.key? formula.disable_reason
|
||||||
|
deprecate_disable_reasons[formula.disable_reason]
|
||||||
|
else
|
||||||
|
deprecate_disable_reasons
|
||||||
|
end
|
||||||
|
|
||||||
|
odie "#{formula.full_name} has been disabled because it #{reason}!"
|
||||||
else
|
else
|
||||||
odie "#{formula.full_name} has been disabled!"
|
odie "#{formula.full_name} has been disabled!"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -46,6 +46,8 @@ module RuboCop
|
|||||||
reason_found = false
|
reason_found = false
|
||||||
reason(node) do |reason_node|
|
reason(node) do |reason_node|
|
||||||
reason_found = true
|
reason_found = true
|
||||||
|
next if reason_node.sym_type?
|
||||||
|
|
||||||
offending_node(reason_node)
|
offending_node(reason_node)
|
||||||
reason_string = string_content(reason_node)
|
reason_string = string_content(reason_node)
|
||||||
|
|
||||||
@ -77,7 +79,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def_node_search :reason, <<~EOS
|
def_node_search :reason, <<~EOS
|
||||||
(pair (sym :because) $str)
|
(pair (sym :because) ${str sym})
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -211,6 +211,15 @@ describe RuboCop::Cop::FormulaAudit::DeprecateDisableReason do
|
|||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "deprecation reason is acceptable as a symbol" do
|
||||||
|
expect_no_offenses(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
url 'https://brew.sh/foo-1.0.tgz'
|
||||||
|
deprecate! because: :does_not_build
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
it "deprecation reason is acceptable with date" do
|
it "deprecation reason is acceptable with date" do
|
||||||
expect_no_offenses(<<~RUBY)
|
expect_no_offenses(<<~RUBY)
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
@ -220,6 +229,15 @@ describe RuboCop::Cop::FormulaAudit::DeprecateDisableReason do
|
|||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "deprecation reason is acceptable as a symbol with date" do
|
||||||
|
expect_no_offenses(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
url 'https://brew.sh/foo-1.0.tgz'
|
||||||
|
deprecate! date: "2020-08-28", because: :does_not_build
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
it "deprecation reason is absent" do
|
it "deprecation reason is absent" do
|
||||||
expect_offense(<<~RUBY)
|
expect_offense(<<~RUBY)
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
@ -349,6 +367,15 @@ describe RuboCop::Cop::FormulaAudit::DeprecateDisableReason do
|
|||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "disable reason is acceptable as a symbol" do
|
||||||
|
expect_no_offenses(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
url 'https://brew.sh/foo-1.0.tgz'
|
||||||
|
disable! because: :does_not_build
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
it "disable reason is acceptable with date" do
|
it "disable reason is acceptable with date" do
|
||||||
expect_no_offenses(<<~RUBY)
|
expect_no_offenses(<<~RUBY)
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
@ -358,6 +385,15 @@ describe RuboCop::Cop::FormulaAudit::DeprecateDisableReason do
|
|||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "disable reason is acceptable as a symbol with date" do
|
||||||
|
expect_no_offenses(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
url 'https://brew.sh/foo-1.0.tgz'
|
||||||
|
disable! date: "2020-08-28", because: :does_not_build
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
it "disable reason is absent" do
|
it "disable reason is absent" do
|
||||||
expect_offense(<<~RUBY)
|
expect_offense(<<~RUBY)
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user