audit: Port audit_options rules for new formulae to rubocop and add test

This commit is contained in:
Gautham Goli 2017-07-15 13:34:16 +05:30
parent 83f61830f6
commit a8f1b02be9
4 changed files with 46 additions and 8 deletions

View File

@ -27,6 +27,9 @@ FormulaAudit/Options:
FormulaAuditStrict/Options:
Enabled: true
NewFormulaAudit/Options:
Enabled: true
FormulaAuditStrict/BottleBlock:
Enabled: true

View File

@ -87,10 +87,14 @@ module Homebrew
if !only_cops.empty?
options[:only_cops] = only_cops
ARGV.push("--only=style")
elsif new_formula
options[:only_cops] = [:FormulaAudit, :FormulaAuditStrict, :NewFormulaAudit]
elsif strict
options[:only_cops] = [:FormulaAudit, :FormulaAuditStrict]
elsif !except_cops.empty?
options[:except_cops] = except_cops
elsif !strict
options[:except_cops] = [:FormulaAuditStrict]
options[:except_cops] = [:FormulaAuditStrict, :NewFormulaAudit]
end
# Check style in a single batch run up front for performance
@ -553,13 +557,6 @@ class FormulaAuditor
problem "keg_only reason should not end with a period."
end
def audit_options
return unless @new_formula
return if formula.deprecated_options.empty?
return if formula.versioned_formula?
problem "New formulae should not use `deprecated_option`."
end
def audit_homepage
homepage = formula.homepage

View File

@ -43,5 +43,16 @@ module RuboCop
end
end
end
module NewFormulaAudit
class Options < FormulaCop
MSG = "New Formula should not use `deprecated_option`".freeze
def audit_formula(_node, _class_node, _parent_class_node, body_node)
return if versioned_formula?
problem MSG if method_called_ever?(body_node, :deprecated_option)
end
end
end
end
end

View File

@ -103,3 +103,30 @@ describe RuboCop::Cop::FormulaAuditStrict::Options do
end
end
end
describe RuboCop::Cop::NewFormulaAudit::Options do
subject(:cop) { described_class.new }
context "When auditing options for a new formula" do
it "with deprecated options" do
source = <<-EOS.undent
class Foo < Formula
url 'http://example.com/foo-1.0.tgz'
deprecated_option "examples" => "with-examples"
end
EOS
expected_offenses = [{ message: described_class::MSG,
severity: :convention,
line: 3,
column: 2,
source: source }]
inspect_source(cop, source)
expected_offenses.zip(cop.offenses).each do |expected, actual|
expect_offense(expected, actual)
end
end
end
end