Class: Pronto::ClangFormatRunner
- Inherits:
-
Runner
- Object
- Runner
- Pronto::ClangFormatRunner
- Defined in:
- lib/pronto/clang_format_runner.rb
Instance Method Summary collapse
- #cpp_file?(file_path) ⇒ Boolean
-
#initialize(_, __ = nil) ⇒ ClangFormatRunner
constructor
A new instance of ClangFormatRunner.
- #inspect(patch) ⇒ Object
- #new_message(offence, line) ⇒ Object
- #run ⇒ Object
- #valid_patch?(patch) ⇒ Boolean
Constructor Details
#initialize(_, __ = nil) ⇒ ClangFormatRunner
Returns a new instance of ClangFormatRunner.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/pronto/clang_format_runner.rb', line 6 def initialize(_, __ = nil) super @inspector = ::Pronto::ClangFormat::Wrapper.new comma_separated_exts = ENV['PRONTO_CLANG_FORMAT_FILE_EXTS'] if comma_separated_exts.nil? # load default cpp files extensions @cpp_extensions = %w[c h cpp cc cxx c++ hh hxx hpp h++ icc inl tcc tpp ipp] else # load desired extensions from environment variable @cpp_extensions = comma_separated_exts.split(',').map(&:strip) end end |
Instance Method Details
#cpp_file?(file_path) ⇒ Boolean
32 33 34 |
# File 'lib/pronto/clang_format_runner.rb', line 32 def cpp_file?(file_path) @cpp_extensions.include? file_path.extname[1..-1] end |
#inspect(patch) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pronto/clang_format_runner.rb', line 36 def inspect(patch) file_path = patch.new_file_full_path offences = @inspector.run(file_path) offences.map do |offence| line = patch.added_lines.find do |added_line| offence.affected_lines_range.cover? added_line.new_lineno end (offence, line) unless line.nil? end end |
#new_message(offence, line) ⇒ Object
47 48 49 50 |
# File 'lib/pronto/clang_format_runner.rb', line 47 def (offence, line) path = line.patch.delta.new_file[:path] Message.new(path, line, :warning, offence.msg, nil, self.class) end |
#run ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/pronto/clang_format_runner.rb', line 18 def run return [] if !@patches || @patches.count.zero? @patches .select { |p| valid_patch?(p) } .map { |p| inspect(p) } .flatten.compact .uniq { || .line } # generate only one message per line end |
#valid_patch?(patch) ⇒ Boolean
27 28 29 30 |
# File 'lib/pronto/clang_format_runner.rb', line 27 def valid_patch?(patch) return false if patch.additions < 1 cpp_file?(patch.new_file_full_path) end |