audit: avoid build-time checks in core

Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Jonathan Chang 2020-01-09 11:45:11 -05:00
parent 9634041f82
commit cf66c05d87
2 changed files with 26 additions and 0 deletions

View File

@ -419,6 +419,21 @@ module RuboCop
problem "Use the `#{match}` Ruby method instead of `#{method.source}`" problem "Use the `#{match}` Ruby method instead of `#{method.source}`"
end end
return if formula_tap != "homebrew-core"
# Avoid build-time checks in homebrew/core
find_every_method_call_by_name(body_node, :system).each do |method|
params = parameters(method)
next unless node_equals?(params[0], "make")
params[1..].each do |arg|
next unless regex_match_group(arg, /^(checks?|tests?)$/)
offending_node(method)
problem "Formulae in homebrew/core should not run build-time checks"
end
end
end end
def modifier?(node) def modifier?(node)

View File

@ -349,6 +349,17 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
subject(:cop) { described_class.new } subject(:cop) { described_class.new }
context "When auditing formula" do context "When auditing formula" do
it "build-time checks in homebrew/core" do
expect_offense(<<~RUBY, "/homebrew-core/")
class Foo < Formula
desc "foo"
url 'https://brew.sh/foo-1.0.tgz'
system "make", "-j1", "test"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Formulae in homebrew/core should not run build-time checks
end
RUBY
end
it "FileUtils usage" do it "FileUtils usage" do
expect_offense(<<~RUBY) expect_offense(<<~RUBY)
class Foo < Formula class Foo < Formula