class Pronto::Infer
Constants
- Offence
Public Instance Methods
run()
click to toggle source
# File lib/pronto/infer.rb, line 8 def run return [] unless @patches @patches .select(&method(:valid_patch?)) .flat_map(&method(:inspect)) .compact end
Private Instance Methods
infer_offences()
click to toggle source
# File lib/pronto/infer.rb, line 43 def infer_offences @infer_offences ||= begin path = File.join(infer_out_dir, 'report.json') read_infer_report(path) end end
infer_out_dir()
click to toggle source
# File lib/pronto/infer.rb, line 21 def infer_out_dir ENV['PRONTO_INFER_OUT_DIR'] || (raise 'Please set `PRONTO_INFER_OUT_DIR` to use pronto-infer') end
infer_project_root_dir()
click to toggle source
# File lib/pronto/infer.rb, line 25 def infer_project_root_dir File.expand_path(ENV['PRONTO_INFER_PROJECT_ROOT_DIR'] || '.') end
inspect(patch)
click to toggle source
# File lib/pronto/infer.rb, line 33 def inspect(patch) offences = infer_offences.select { |offence| offence.path == patch.new_file_full_path.to_s } offences.flat_map do |offence| patch.added_lines .select { |line| line.new_lineno == offence.line } .map { |line| new_message(offence, line) } end end
new_message(offence, line)
click to toggle source
# File lib/pronto/infer.rb, line 58 def new_message(offence, line) path = line.patch.delta.new_file[:path] Message.new(path, line, :warning, offence.message, nil, self.class) end
read_infer_report(path)
click to toggle source
# File lib/pronto/infer.rb, line 51 def read_infer_report(path) report = JSON.parse(File.read(path)) report.map do |r| Offence.new(File.join(infer_project_root_dir, r['file']), r['line'], r['qualifier']) end end
valid_patch?(patch)
click to toggle source
# File lib/pronto/infer.rb, line 29 def valid_patch?(patch) patch.additions.positive? end