From 32bc5535b6e365959bdf88533cdfa5e1271ea6fa Mon Sep 17 00:00:00 2001 From: Gautham Goli <goligautham@gmail.com> Date: Tue, 28 Aug 2018 23:09:44 +0530 Subject: [PATCH] style: Fix npe and add test for corrected offense results --- Library/Homebrew/dev-cmd/audit.rb | 2 +- Library/Homebrew/style.rb | 2 +- Library/Homebrew/test/cmd/style_spec.rb | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index e2b40f643e..9c5900d349 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -130,7 +130,7 @@ module Homebrew formula_count += 1 problem_count += fa.problems.size problem_lines = format_problem_lines(fa.problems) - corrected_problem_count = options.fetch(:style_offenses, []).count(&:corrected?) + corrected_problem_count = options[:style_offenses].count(&:corrected?) new_formula_problem_lines = format_problem_lines(fa.new_formula_problems) if args.display_filename? puts problem_lines.map { |s| "#{f.path}: #{s}" } diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index ce176e72b7..5e3534f0e0 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -119,7 +119,7 @@ module Homebrew end def file_offenses(path) - @file_offenses[path.to_s] + @file_offenses.fetch(path.to_s, []) end end diff --git a/Library/Homebrew/test/cmd/style_spec.rb b/Library/Homebrew/test/cmd/style_spec.rb index 64f1bb594d..4f0edfb7a4 100644 --- a/Library/Homebrew/test/cmd/style_spec.rb +++ b/Library/Homebrew/test/cmd/style_spec.rb @@ -30,6 +30,30 @@ describe "brew style" do expect(rubocop_result.file_offenses(formula.realpath.to_s).map(&:message)) .to include("Extra empty line detected at class body beginning.") end + + it "corrected offense output format" do + formula = dir/"my-formula-2.rb" + + formula.write <<~EOS + class MyFormula2 < Formula + desc "Test formula" + homepage "https://foo.org" + url "https://foo.org/foo-1.7.5.tgz" + sha256 "cc692fb9dee0cc288757e708fc1a3b6b56ca1210ca181053a371cb11746969da" + + depends_on "foo" + depends_on "bar-config" => :build + + test do + assert_equal 5, 5 + end + end + EOS + options = { fix: true, only_cops: ["NewFormulaAudit/DependencyOrder"], realpath: true } + rubocop_result = Homebrew::Style.check_style_json([formula], options) + offense_string = rubocop_result.file_offenses(formula.realpath).first.to_s + expect(offense_string).to match(/\[Corrected\]/) + end end describe "Homebrew::check_style_and_print" do -- GitLab