Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Fix npe and add test for corrected offense results #4770

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def audit
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?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this going to have the problem from before again or is it always set now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always set

@file_offenses.fetch(path.to_s, [])

new_formula_problem_lines = format_problem_lines(fa.new_formula_problems)
if args.display_filename?
puts problem_lines.map { |s| "#{f.path}: #{s}" }
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def initialize(json)
end

def file_offenses(path)
@file_offenses[path.to_s]
@file_offenses.fetch(path.to_s, [])
end
end

Expand Down
24 changes: 24 additions & 0 deletions Library/Homebrew/test/cmd/style_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ class MyFormula < Formula
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
Expand Down