class Pronto::Textlint::Runner

Public Instance Methods

run() click to toggle source
# File lib/pronto/textlint/runner.rb, line 9
def run
  return [] unless @patches

  @patches.select(&method(:valid_patch?))
    .flat_map(&method(:inspect))
    .compact
end

Private Instance Methods

clean_up_textlint_output(output) click to toggle source
# File lib/pronto/textlint/runner.rb, line 59
def clean_up_textlint_output(output)
  output.flat_map do |offence|
    offence['messages'].map do |message|
      message.merge('path' => offence['filePath'])
    end
  end
end
config_path() click to toggle source
# File lib/pronto/textlint/runner.rb, line 23
def config_path
  ENV['PRONTO_TEXTLINT_CONFIG_PATH'] || '.textlintrc'
end
inspect(patch) click to toggle source
# File lib/pronto/textlint/runner.rb, line 31
def inspect(patch)
  output = run_textlint(patch)
  offences = clean_up_textlint_output(output)

  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/textlint/runner.rb, line 54
def new_message(offence, line)
  path = line.patch.delta.new_file[:path]
  Message.new(path, line, :warning, offence['message'], nil, self.class)
end
run_textlint(patch) click to toggle source
# File lib/pronto/textlint/runner.rb, line 42
def run_textlint(patch)
  Dir.chdir(patch.repo.path) do
    path = patch.new_file_full_path.to_s
    command = "#{textlint_path.shellescape} -f json -c #{config_path} #{path.shellescape}"
    stdout, stderr, = Open3.capture3(command)
    puts "WARN: pronto-textlint: #{stderr}" if stderr && !stderr.empty?

    return [] if stdout.nil?
    JSON.parse(stdout)
  end
end
textlint_path() click to toggle source
# File lib/pronto/textlint/runner.rb, line 19
def textlint_path
  ENV['PRONTO_TEXTLINT_PATH'] || 'textlint'
end
valid_patch?(patch) click to toggle source
# File lib/pronto/textlint/runner.rb, line 27
def valid_patch?(patch)
  patch.additions > 0
end