Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GauthamGoli I've disabled this in 207ffd6 as it was activating for every formula every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into it now.


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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline after MSG (and in general can you go and fix that up for any other occurrences in this or other cops?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(feel free to do all of them in this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and found no recurrence in other cops.


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