diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index 92d02b3b69..1a2c32d200 100644 --- a/Library/Homebrew/rubocops/lines.rb +++ b/Library/Homebrew/rubocops/lines.rb @@ -419,6 +419,21 @@ module RuboCop problem "Use the `#{match}` Ruby method instead of `#{method.source}`" 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 def modifier?(node) diff --git a/Library/Homebrew/test/rubocops/lines_spec.rb b/Library/Homebrew/test/rubocops/lines_spec.rb index 5e10d89f7a..9885bbc8fb 100644 --- a/Library/Homebrew/test/rubocops/lines_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_spec.rb @@ -349,6 +349,17 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do subject(:cop) { described_class.new } 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 expect_offense(<<~RUBY) class Foo < Formula