Skip to content
Snippets Groups Projects
Unverified Commit 32bc5535 authored by Gautham Goli's avatar Gautham Goli
Browse files

style: Fix npe and add test for corrected offense results

parent b707d2a2
No related branches found
No related tags found
No related merge requests found
......@@ -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}" }
......
......@@ -119,7 +119,7 @@ module Homebrew
end
def file_offenses(path)
@file_offenses[path.to_s]
@file_offenses.fetch(path.to_s, [])
end
end
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment