Merge pull request #8530 from Rylan12/fix-disable-and-deprecate-reasons
Fix disable and deprecate reasons
This commit is contained in:
commit
2a4c9f610e
@ -1151,7 +1151,7 @@ class Formula
|
||||
# The reason this {Formula} is deprecated.
|
||||
# Returns `nil` if no reason is specified or the formula is not deprecated.
|
||||
# @method deprecation_reason
|
||||
# @return [String]
|
||||
# @return [String, Symbol]
|
||||
delegate deprecation_reason: :"self.class"
|
||||
|
||||
# Whether this {Formula} is disabled (i.e. cannot be installed).
|
||||
@ -1163,7 +1163,7 @@ class Formula
|
||||
# The reason this {Formula} is disabled.
|
||||
# Returns `nil` if no reason is specified or the formula is not disabled.
|
||||
# @method disable_reason
|
||||
# @return [String]
|
||||
# @return [String, Symbol]
|
||||
delegate disable_reason: :"self.class"
|
||||
|
||||
def skip_cxxstdlib_check?
|
||||
@ -2778,7 +2778,8 @@ class Formula
|
||||
# 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
|
||||
# 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)
|
||||
# TODO: enable for next major/minor release
|
||||
# odeprecated "`deprecate!` without a reason", "`deprecate! because: \"reason\"`" if because.blank?
|
||||
@ -2798,13 +2799,14 @@ class Formula
|
||||
|
||||
# The reason for deprecation of a {Formula}.
|
||||
# Returns `nil` if no reason was provided or the formula is not deprecated.
|
||||
# @return [String]
|
||||
# @return [String, Symbol]
|
||||
attr_reader :deprecation_reason
|
||||
|
||||
# Disables a {Formula} (on a given date, if provided) so it cannot be
|
||||
# installed. If the date has not yet passed the formula
|
||||
# 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)
|
||||
# TODO: enable for next major/minor release
|
||||
# odeprecated "`disable!` without a reason", "`disable! because: \"reason\"`" if because.blank?
|
||||
@ -2828,7 +2830,7 @@ class Formula
|
||||
|
||||
# The reason for a {Formula} is disabled.
|
||||
# Returns `nil` if no reason was provided or the formula is not disabled.
|
||||
# @return [String]
|
||||
# @return [String, Symbol]
|
||||
attr_reader :disable_reason
|
||||
|
||||
# @private
|
||||
|
@ -202,15 +202,38 @@ class FormulaInstaller
|
||||
def check_install_sanity
|
||||
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.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
|
||||
opoo "#{formula.full_name} has been deprecated!"
|
||||
end
|
||||
elsif formula.disabled?
|
||||
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
|
||||
odie "#{formula.full_name} has been disabled!"
|
||||
end
|
||||
|
@ -22,6 +22,6 @@ require "rubocops/uses_from_macos"
|
||||
require "rubocops/files"
|
||||
require "rubocops/keg_only"
|
||||
require "rubocops/version"
|
||||
require "rubocops/deprecate"
|
||||
require "rubocops/deprecate_disable"
|
||||
|
||||
require "rubocops/rubocop-cask"
|
||||
|
@ -1,37 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rubocops/extend/formula"
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module FormulaAudit
|
||||
# This cop audits deprecate! date
|
||||
class DeprecateDate < FormulaCop
|
||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||
deprecate_node = find_node_method_by_name(body_node, :deprecate!)
|
||||
|
||||
return if deprecate_node.nil?
|
||||
|
||||
deprecate_date(deprecate_node) do |date_node|
|
||||
Date.iso8601(string_content(date_node))
|
||||
rescue ArgumentError
|
||||
fixed_date_string = Date.parse(string_content(date_node)).iso8601
|
||||
offending_node(date_node)
|
||||
problem "Use `#{fixed_date_string}` to comply with ISO 8601"
|
||||
end
|
||||
end
|
||||
|
||||
def autocorrect(node)
|
||||
lambda do |corrector|
|
||||
fixed_fixed_date_string = Date.parse(string_content(node)).iso8601
|
||||
corrector.replace(node.source_range, "\"#{fixed_fixed_date_string}\"")
|
||||
end
|
||||
end
|
||||
|
||||
def_node_search :deprecate_date, <<~EOS
|
||||
(pair (sym :date) $str)
|
||||
EOS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
87
Library/Homebrew/rubocops/deprecate_disable.rb
Normal file
87
Library/Homebrew/rubocops/deprecate_disable.rb
Normal file
@ -0,0 +1,87 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rubocops/extend/formula"
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module FormulaAudit
|
||||
# This cop audits deprecate! date and disable! date
|
||||
class DeprecateDisableDate < FormulaCop
|
||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||
[:deprecate!, :disable!].each do |method|
|
||||
node = find_node_method_by_name(body_node, method)
|
||||
|
||||
next if node.nil?
|
||||
|
||||
date(node) do |date_node|
|
||||
Date.iso8601(string_content(date_node))
|
||||
rescue ArgumentError
|
||||
fixed_date_string = Date.parse(string_content(date_node)).iso8601
|
||||
offending_node(date_node)
|
||||
problem "Use `#{fixed_date_string}` to comply with ISO 8601"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def autocorrect(node)
|
||||
lambda do |corrector|
|
||||
fixed_fixed_date_string = Date.parse(string_content(node)).iso8601
|
||||
corrector.replace(node.source_range, "\"#{fixed_fixed_date_string}\"")
|
||||
end
|
||||
end
|
||||
|
||||
def_node_search :date, <<~EOS
|
||||
(pair (sym :date) $str)
|
||||
EOS
|
||||
end
|
||||
|
||||
# This cop audits deprecate! reason
|
||||
class DeprecateDisableReason < FormulaCop
|
||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||
[:deprecate!, :disable!].each do |method|
|
||||
node = find_node_method_by_name(body_node, method)
|
||||
|
||||
next if node.nil?
|
||||
|
||||
reason_found = false
|
||||
reason(node) do |reason_node|
|
||||
reason_found = true
|
||||
next if reason_node.sym_type?
|
||||
|
||||
offending_node(reason_node)
|
||||
reason_string = string_content(reason_node)
|
||||
|
||||
problem "Do not start the reason with `it`" if reason_string.start_with?("it ")
|
||||
|
||||
problem "Do not end the reason with a punctuation mark" if %w[. ! ?].include?(reason_string[-1])
|
||||
end
|
||||
|
||||
next if reason_found
|
||||
|
||||
case method
|
||||
when :deprecate!
|
||||
problem 'Add a reason for deprecation: `deprecate! because: "..."`'
|
||||
when :disable!
|
||||
problem 'Add a reason for disabling: `disable! because: "..."`'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def autocorrect(node)
|
||||
return unless node.str_type?
|
||||
|
||||
lambda do |corrector|
|
||||
reason = string_content(node)
|
||||
reason = reason[3..] if reason.start_with?("it ")
|
||||
reason.chop! if %w[. ! ?].include?(reason[-1])
|
||||
corrector.replace(node.source_range, "\"#{reason}\"")
|
||||
end
|
||||
end
|
||||
|
||||
def_node_search :reason, <<~EOS
|
||||
(pair (sym :because) ${str sym})
|
||||
EOS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -635,7 +635,7 @@ false:
|
||||
- ./test/rubocops/components_redundancy_spec.rb
|
||||
- ./test/rubocops/conflicts_spec.rb
|
||||
- ./test/rubocops/dependency_order_spec.rb
|
||||
- ./test/rubocops/deprecate_spec.rb
|
||||
- ./test/rubocops/deprecate_disable_spec.rb
|
||||
- ./test/rubocops/formula_desc_spec.rb
|
||||
- ./test/rubocops/homepage_spec.rb
|
||||
- ./test/rubocops/lines_spec.rb
|
||||
@ -895,7 +895,7 @@ true:
|
||||
- ./rubocops/cask/constants/stanza.rb
|
||||
- ./rubocops/cask/desc.rb
|
||||
- ./rubocops/cask/extend/string.rb
|
||||
- ./rubocops/deprecate.rb
|
||||
- ./rubocops/deprecate_disable.rb
|
||||
- ./tap_constants.rb
|
||||
- ./test/support/helper/fixtures.rb
|
||||
- ./test/support/lib/config.rb
|
||||
|
@ -21,7 +21,7 @@ RSpec/InstanceVariable:
|
||||
- 'utils/git_spec.rb'
|
||||
- 'version_spec.rb'
|
||||
|
||||
# Offense count: 75
|
||||
# Offense count: 76
|
||||
RSpec/MultipleDescribes:
|
||||
Exclude:
|
||||
- 'ENV_spec.rb'
|
||||
@ -93,6 +93,7 @@ RSpec/MultipleDescribes:
|
||||
- 'patch_spec.rb'
|
||||
- 'rubocops/checksum_spec.rb'
|
||||
- 'rubocops/class_spec.rb'
|
||||
- 'rubocops/deprecate_disable_spec.rb'
|
||||
- 'rubocops/formula_desc_spec.rb'
|
||||
- 'rubocops/lines_spec.rb'
|
||||
- 'rubocops/text_spec.rb'
|
||||
|
515
Library/Homebrew/test/rubocops/deprecate_disable_spec.rb
Normal file
515
Library/Homebrew/test/rubocops/deprecate_disable_spec.rb
Normal file
@ -0,0 +1,515 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rubocops/deprecate_disable"
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::DeprecateDisableDate do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "When auditing formula for deprecate! date:" do
|
||||
it "deprecation date is not ISO 8601 compliant" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! date: "June 25, 2020"
|
||||
^^^^^^^^^^^^^^^ Use `2020-06-25` to comply with ISO 8601
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation date is not ISO 8601 compliant with reason" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken", date: "June 25, 2020"
|
||||
^^^^^^^^^^^^^^^ Use `2020-06-25` to comply with ISO 8601
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation date is ISO 8601 compliant" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! date: "2020-06-25"
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation date is ISO 8601 compliant with reason" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken", date: "2020-06-25"
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "no deprecation date" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate!
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "no deprecation date with reason" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken"
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "auto corrects to ISO 8601 format" do
|
||||
source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! date: "June 25, 2020"
|
||||
end
|
||||
RUBY
|
||||
|
||||
corrected_source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! date: "2020-06-25"
|
||||
end
|
||||
RUBY
|
||||
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
|
||||
it "auto corrects to ISO 8601 format with reason" do
|
||||
source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken", date: "June 25, 2020"
|
||||
end
|
||||
RUBY
|
||||
|
||||
corrected_source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken", date: "2020-06-25"
|
||||
end
|
||||
RUBY
|
||||
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
end
|
||||
|
||||
context "When auditing formula for disable! date:" do
|
||||
it "disable date is not ISO 8601 compliant" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! date: "June 25, 2020"
|
||||
^^^^^^^^^^^^^^^ Use `2020-06-25` to comply with ISO 8601
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "disable date is not ISO 8601 compliant with reason" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "is broken", date: "June 25, 2020"
|
||||
^^^^^^^^^^^^^^^ Use `2020-06-25` to comply with ISO 8601
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "disable date is ISO 8601 compliant" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! date: "2020-06-25"
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "disable date is ISO 8601 compliant with reason" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "is broken", date: "2020-06-25"
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "no disable date" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable!
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "no disable date with reason" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "is broken"
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "auto corrects to ISO 8601 format" do
|
||||
source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! date: "June 25, 2020"
|
||||
end
|
||||
RUBY
|
||||
|
||||
corrected_source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! date: "2020-06-25"
|
||||
end
|
||||
RUBY
|
||||
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
|
||||
it "auto corrects to ISO 8601 format with reason" do
|
||||
source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "is broken", date: "June 25, 2020"
|
||||
end
|
||||
RUBY
|
||||
|
||||
corrected_source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "is broken", date: "2020-06-25"
|
||||
end
|
||||
RUBY
|
||||
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::DeprecateDisableReason do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "When auditing formula for deprecate! because:" do
|
||||
it "deprecation reason is acceptable" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken"
|
||||
end
|
||||
RUBY
|
||||
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
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! date: "2020-08-28", because: "is broken"
|
||||
end
|
||||
RUBY
|
||||
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
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate!
|
||||
^^^^^^^^^^ Add a reason for deprecation: `deprecate! because: "..."`
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation reason is absent with date" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! date: "2020-08-28"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add a reason for deprecation: `deprecate! because: "..."`
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation reason starts with `it`" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "it is broken"
|
||||
^^^^^^^^^^^^^^ Do not start the reason with `it`
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation reason starts with `it` with date" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! date: "2020-08-28", because: "it is broken"
|
||||
^^^^^^^^^^^^^^ Do not start the reason with `it`
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation reason ends with a period" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken."
|
||||
^^^^^^^^^^^^ Do not end the reason with a punctuation mark
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation reason ends with an exclamation point" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken!"
|
||||
^^^^^^^^^^^^ Do not end the reason with a punctuation mark
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation reason ends with a question mark" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken?"
|
||||
^^^^^^^^^^^^ Do not end the reason with a punctuation mark
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation reason ends with a period with date" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! date: "2020-08-28", because: "is broken."
|
||||
^^^^^^^^^^^^ Do not end the reason with a punctuation mark
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "auto corrects to remove `it`" do
|
||||
source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "it is broken"
|
||||
end
|
||||
RUBY
|
||||
|
||||
corrected_source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken"
|
||||
end
|
||||
RUBY
|
||||
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
|
||||
it "auto corrects to remove punctuation" do
|
||||
source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken."
|
||||
end
|
||||
RUBY
|
||||
|
||||
corrected_source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken"
|
||||
end
|
||||
RUBY
|
||||
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
end
|
||||
|
||||
context "When auditing formula for disable! because:" do
|
||||
it "disable reason is acceptable" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "is broken"
|
||||
end
|
||||
RUBY
|
||||
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
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! date: "2020-08-28", because: "is broken"
|
||||
end
|
||||
RUBY
|
||||
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
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable!
|
||||
^^^^^^^^ Add a reason for disabling: `disable! because: "..."`
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "disable reason is absent with date" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! date: "2020-08-28"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add a reason for disabling: `disable! because: "..."`
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "disable reason starts with `it`" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "it is broken"
|
||||
^^^^^^^^^^^^^^ Do not start the reason with `it`
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "disable reason starts with `it` with date" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! date: "2020-08-28", because: "it is broken"
|
||||
^^^^^^^^^^^^^^ Do not start the reason with `it`
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "disable reason ends with a period" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "is broken."
|
||||
^^^^^^^^^^^^ Do not end the reason with a punctuation mark
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "disable reason ends with an exclamation point" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "is broken!"
|
||||
^^^^^^^^^^^^ Do not end the reason with a punctuation mark
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "disable reason ends with a question mark" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "is broken?"
|
||||
^^^^^^^^^^^^ Do not end the reason with a punctuation mark
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "disable reason ends with a period with date" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! date: "2020-08-28", because: "is broken."
|
||||
^^^^^^^^^^^^ Do not end the reason with a punctuation mark
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "auto corrects to remove `it`" do
|
||||
source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "it is broken"
|
||||
end
|
||||
RUBY
|
||||
|
||||
corrected_source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "is broken"
|
||||
end
|
||||
RUBY
|
||||
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
|
||||
it "auto corrects to remove punctuation" do
|
||||
source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "is broken."
|
||||
end
|
||||
RUBY
|
||||
|
||||
corrected_source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
disable! because: "is broken"
|
||||
end
|
||||
RUBY
|
||||
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
end
|
||||
end
|
@ -1,103 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rubocops/deprecate"
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::DeprecateDate do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "When auditing formula for deprecate! date:" do
|
||||
it "deprecation date is not ISO 8601 compliant" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! date: "June 25, 2020"
|
||||
^^^^^^^^^^^^^^^ Use `2020-06-25` to comply with ISO 8601
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation date is not ISO 8601 compliant with reason" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken", date: "June 25, 2020"
|
||||
^^^^^^^^^^^^^^^ Use `2020-06-25` to comply with ISO 8601
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation date is ISO 8601 compliant" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! date: "2020-06-25"
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "deprecation date is ISO 8601 compliant with reason" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken", date: "2020-06-25"
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "no deprecation date" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate!
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "no deprecation date with reason" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken"
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "auto corrects to ISO 8601 format" do
|
||||
source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! date: "June 25, 2020"
|
||||
end
|
||||
RUBY
|
||||
|
||||
corrected_source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! date: "2020-06-25"
|
||||
end
|
||||
RUBY
|
||||
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
|
||||
it "auto corrects to ISO 8601 format with reason" do
|
||||
source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken", date: "June 25, 2020"
|
||||
end
|
||||
RUBY
|
||||
|
||||
corrected_source = <<~RUBY
|
||||
class Foo < Formula
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
deprecate! because: "is broken", date: "2020-06-25"
|
||||
end
|
||||
RUBY
|
||||
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user