class Pronto::ClangTidy::Parser
a class that provides functions to parse a clang-tidy output file and returns an array of Offence
objects
Private Class Methods
new(output_filename)
click to toggle source
# File lib/pronto/clang_tidy/parser.rb, line 6 def initialize(output_filename) @output_filename = output_filename end
Private Instance Methods
group_diagnostics(diags)
click to toggle source
turns an array of diagnostics into an array of offences by grouping note-level diagnostics with their corresponding diagnostic
# File lib/pronto/clang_tidy/parser.rb, line 40 def group_diagnostics(diags) offences = [] diags.each do |diag| if diag.level != :note offences << Offence.new(diag) else offences.last << diag unless offences.empty? end end offences end
parse_clang_tidy_output(output)
click to toggle source
parses clang-tidy output and returns a list of offences
# File lib/pronto/clang_tidy/parser.rb, line 22 def parse_clang_tidy_output(output) # a regular expression that matches diagnostics' headers header_regexp = Regexp.new '(?<filename>^/[^:]+):(?<line_no>\d+):' \ '(?<col_no>\d+): (?<level>[^:]+): ' \ '(?<message>.+$)' diagnostics = [] output.each_line do |line| if (match_data = header_regexp.match(line)) diagnostics << Diagnostic.new(*match_data.captures) else diagnostics.last.hints << line unless diagnostics.empty? end end group_diagnostics(diagnostics) end
read_clang_tidy_output()
click to toggle source
reads clang-tidy output file and returns an array of offences
# File lib/pronto/clang_tidy/parser.rb, line 11 def read_clang_tidy_output unless FileTest.file? @output_filename puts 'WARN: pronto-clang_tidy: clang-tidy output file not found' return [] end parse_clang_tidy_output File.read(@output_filename) end