class CukeLinter::PrettyFormatter
Formats linting data into organized, user readable text
Public Instance Methods
format(data)
click to toggle source
Formats the given linting data
# File lib/cuke_linter/formatters/pretty_formatter.rb, line 7 def format(data) format_data(categorize_problems(data), data.count) end
Private Instance Methods
categorize_problems(data)
click to toggle source
# File lib/cuke_linter/formatters/pretty_formatter.rb, line 15 def categorize_problems(data) {}.tap do |categorized_problems| data.each do |lint_item| categorized_problems[lint_item[:linter]] ||= {} categorized_problems[lint_item[:linter]][lint_item[:problem]] ||= [] categorized_problems[lint_item[:linter]][lint_item[:problem]] << lint_item[:location] end end end
compare_locations(file_name_1, file_name_2, line_number_1, line_number_2)
click to toggle source
# File lib/cuke_linter/formatters/pretty_formatter.rb, line 55 def compare_locations(file_name_1, file_name_2, line_number_1, line_number_2) if earlier_file(file_name_1, file_name_2) || same_file_earlier_line(file_name_1, file_name_2, line_number_1, line_number_2) -1 elsif later_file(file_name_1, file_name_2) || same_file_later_line(file_name_1, file_name_2, line_number_1, line_number_2) 1 else 0 end end
earlier_file(file_name_1, file_name_2)
click to toggle source
# File lib/cuke_linter/formatters/pretty_formatter.rb, line 67 def earlier_file(file_name_1, file_name_2) (file_name_1 < file_name_2) end
format_data(problem_data, problem_count)
click to toggle source
# File lib/cuke_linter/formatters/pretty_formatter.rb, line 25 def format_data(problem_data, problem_count) ''.tap do |formatted_data| problem_data.each_pair do |linter, problems| formatted_data << "#{linter}\n" problems.each_pair do |problem, locations| formatted_data << " #{problem}\n" sort_locations(locations).each do |location| formatted_data << " #{location}\n" end end end formatted_data << "\n" unless problem_count.zero? formatted_data << "#{problem_count} issues found" end end
later_file(file_name_1, file_name_2)
click to toggle source
# File lib/cuke_linter/formatters/pretty_formatter.rb, line 75 def later_file(file_name_1, file_name_2) (file_name_1 > file_name_2) end
same_file_earlier_line(file_name_1, file_name_2, line_number_1, line_number_2)
click to toggle source
# File lib/cuke_linter/formatters/pretty_formatter.rb, line 71 def same_file_earlier_line(file_name_1, file_name_2, line_number_1, line_number_2) (file_name_1 == file_name_2) && (line_number_1 < line_number_2) end
same_file_later_line(file_name_1, file_name_2, line_number_1, line_number_2)
click to toggle source
# File lib/cuke_linter/formatters/pretty_formatter.rb, line 79 def same_file_later_line(file_name_1, file_name_2, line_number_1, line_number_2) (file_name_1 == file_name_2) && (line_number_1 > line_number_2) end
sort_locations(locations)
click to toggle source
# File lib/cuke_linter/formatters/pretty_formatter.rb, line 44 def sort_locations(locations) locations.sort do |a, b| file_name_1 = a.match(/(.*?)(?::\d+)?$/)[1] line_number_1 = a =~ /:\d+$/ ? a.match(/:(\d+)$/)[1].to_i : 0 file_name_2 = b.match(/(.*?)(?::\d+)?$/)[1] line_number_2 = b =~ /:\d+$/ ? b.match(/:(\d+)$/)[1].to_i : 0 compare_locations(file_name_1, file_name_2, line_number_1, line_number_2) end end