style: Fix npe and add test for corrected offense results
This commit is contained in:
		
							parent
							
								
									b707d2a232
								
							
						
					
					
						commit
						32bc5535b6
					
				| @ -130,7 +130,7 @@ module Homebrew | |||||||
|       formula_count += 1 |       formula_count += 1 | ||||||
|       problem_count += fa.problems.size |       problem_count += fa.problems.size | ||||||
|       problem_lines = format_problem_lines(fa.problems) |       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) |       new_formula_problem_lines = format_problem_lines(fa.new_formula_problems) | ||||||
|       if args.display_filename? |       if args.display_filename? | ||||||
|         puts problem_lines.map { |s| "#{f.path}: #{s}" } |         puts problem_lines.map { |s| "#{f.path}: #{s}" } | ||||||
|  | |||||||
| @ -119,7 +119,7 @@ module Homebrew | |||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       def file_offenses(path) |       def file_offenses(path) | ||||||
|         @file_offenses[path.to_s] |         @file_offenses.fetch(path.to_s, []) | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -30,6 +30,30 @@ describe "brew style" do | |||||||
|       expect(rubocop_result.file_offenses(formula.realpath.to_s).map(&:message)) |       expect(rubocop_result.file_offenses(formula.realpath.to_s).map(&:message)) | ||||||
|         .to include("Extra empty line detected at class body beginning.") |         .to include("Extra empty line detected at class body beginning.") | ||||||
|     end |     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 |   end | ||||||
| 
 | 
 | ||||||
|   describe "Homebrew::check_style_and_print" do |   describe "Homebrew::check_style_and_print" do | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Gautham Goli
						Gautham Goli