brew style: assume files under Library are no-formulae

This commit is contained in:
Andrew Janke 2018-06-11 15:10:59 -04:00
parent 3081390ff8
commit c0b7aa00e4
2 changed files with 29 additions and 3 deletions

View File

@ -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

View File

@ -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