Skip to content

Commit

Permalink
audit: Port audit_options rules for new formulae to rubocop and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
GauthamGoli committed Jul 15, 2017
1 parent 83f6183 commit a8f1b02
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Library/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ FormulaAudit/Options:
FormulaAuditStrict/Options:
Enabled: true

NewFormulaAudit/Options:
Enabled: true

FormulaAuditStrict/BottleBlock:
Enabled: true

Expand Down
13 changes: 5 additions & 8 deletions Library/Homebrew/dev-cmd/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ def audit
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
Expand Down Expand Up @@ -553,13 +557,6 @@ def audit_keg_only_style
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

Expand Down
11 changes: 11 additions & 0 deletions Library/Homebrew/rubocops/options_cop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,16 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
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
27 changes: 27 additions & 0 deletions Library/Homebrew/test/rubocops/options_cop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,30 @@ class Foo < Formula
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

0 comments on commit a8f1b02

Please sign in to comment.