diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index 92d02b3b69f31da3d98631c96f057be4ccc72de9..1a2c32d200201c4e9156cd8b6d0cce6f5c0b1013 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 5e10d89f7ab82690cb32fb6be62fe0f1f542b373..9885bbc8fb58d3e0763b02cb1f1580d27e0d242d 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