From c0b7aa00e44239085b406c24cc22c84f0af11435 Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Mon, 11 Jun 2018 15:10:59 -0400 Subject: [PATCH] brew style: assume files under Library are no-formulae --- Library/Homebrew/style.rb | 18 +++++++++++++++--- Library/Homebrew/test/cmd/style_spec.rb | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index 71d291b262..c17239b3f0 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -57,12 +57,24 @@ module Homebrew args << "--only" << cops_to_include.join(",") end + has_non_formula = Array(files).any? do |file| + File.expand_path(file).start_with? HOMEBREW_LIBRARY_PATH + end + config_file = if files.nil? || has_non_formula + if ARGV.include?("--rspec") + HOMEBREW_LIBRARY_PATH/".rubocop-rspec.yml" + else + HOMEBREW_LIBRARY_PATH/".rubocop.yml" + end + else + HOMEBREW_LIBRARY/".rubocop_audit.yml" + end + + args << "--config" << config_file + if files.nil? - config_file = ARGV.include?("--rspec") ? ".rubocop-rspec.yml" : ".rubocop.yml" - args << "--config" << HOMEBREW_LIBRARY_PATH/config_file args << HOMEBREW_LIBRARY_PATH else - args << "--config" << HOMEBREW_LIBRARY/".rubocop_audit.yml" args += files end diff --git a/Library/Homebrew/test/cmd/style_spec.rb b/Library/Homebrew/test/cmd/style_spec.rb index c8ccbfbac8..64f1bb594d 100644 --- a/Library/Homebrew/test/cmd/style_spec.rb +++ b/Library/Homebrew/test/cmd/style_spec.rb @@ -31,4 +31,18 @@ describe "brew style" do .to include("Extra empty line detected at class body beginning.") end end + + describe "Homebrew::check_style_and_print" do + let(:dir) { mktmpdir } + + it "returns false for conforming file with only audit-level violations" do + # This file is known to use non-rocket hashes and other things that trigger audit, + # but not regular, cop violations + target_file = HOMEBREW_LIBRARY_PATH/"utils.rb" + + rubocop_result = Homebrew::Style.check_style_and_print([target_file]) + + expect(rubocop_result).to eq false + end + end end