Merge pull request #4304 from apjanke/rspec-implies-non-formula-files

brew style: assume file args are non-formulae when passed --rspec
This commit is contained in:
Mike McQuaid 2018-06-14 09:11:42 +01:00 committed by GitHub
commit c6b6b31d66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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