Class: Pronto::Sorbet::Runner

Inherits:
Runner
  • Object
show all
Defined in:
lib/pronto/sorbet.rb

Constant Summary collapse

SEVERITY =
:warning

Instance Method Summary collapse

Instance Method Details

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pronto/sorbet.rb', line 31

def run
  return [] unless ruby_patches.any?

  sorbet_errors.map do |error|
    patch = ruby_patches.find do |patch|
      patch.new_file_full_path.relative_path_from(repo_path).to_s == error[:filename]
    end
    next if patch.nil?

    line = patch.added_lines.find { |l| l.new_lineno == error[:line] } || patch.added_lines.first
    next if line.nil?

    Message.new(line.patch.delta.new_file[:path], line, SEVERITY,
                "#{error[:message]}\n#{error[:details]}", nil, self.class)
  end.compact
end

#sorbet_errorsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pronto/sorbet.rb', line 17

def sorbet_errors
  Dir.chdir(repo_path) do
    output, _ = Open3.capture2e(sorbet_executable, 'tc')

    output.split("\n")[0..-2].slice_after { |l| l.strip.empty? }.map do |lines|
      filename, line, message = lines.first.split(':', 3)
      { filename: filename, line: line.to_i, message: message.lstrip,
        details: lines[1..-1].join("\n").rstrip }
    end
  end
rescue SystemCallError
  []
end

#sorbet_executableObject



10
11
12
13
14
15
# File 'lib/pronto/sorbet.rb', line 10

def sorbet_executable
  @sorbet_executable ||= begin
    path = `git config pronto.sorbet`.strip
    !path.empty? && File.executable?(path) ? path : 'srb'
  end
end