From cf66c05d871d8f8d4a1f5d224ab4baf60e1dbbeb Mon Sep 17 00:00:00 2001 From: Jonathan Chang Date: Thu, 9 Jan 2020 11:45:11 -0500 Subject: [PATCH] audit: avoid build-time checks in core Co-Authored-By: Mike McQuaid --- Library/Homebrew/rubocops/lines.rb | 15 +++++++++++++++ Library/Homebrew/test/rubocops/lines_spec.rb | 11 +++++++++++ 2 files changed, 26 insertions(+) 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