class Pronto::Markdownlint

Public Instance Methods

run() click to toggle source
# File lib/pronto/markdownlint.rb, line 7
def run
  return [] if !@patches || @patches.count.zero?

  @patches
    .select { |patch| patch.additions > 0 }
    .select { |patch| style_file?(patch.new_file_full_path) }
    .map { |patch| inspect(patch) }
    .flatten.compact
end

Private Instance Methods

inspect(patch) click to toggle source
# File lib/pronto/markdownlint.rb, line 23
def inspect(patch)
  offences = run_stylelint(patch)

  offences.map do |offence|
    patch
      .added_lines
      .select { |line| line.new_lineno == offence["lineNumber"] }
      .map { |line| new_message(offence, line) }
  end
end
new_message(offence, line) click to toggle source
# File lib/pronto/markdownlint.rb, line 40
def new_message(offence, line)
  path = line.patch.delta.new_file[:path]
  Message.new(path, line, :warning, offence_message(offence), nil, self.class)
end
offence_message(offence) click to toggle source
# File lib/pronto/markdownlint.rb, line 34
def offence_message(offence)
  message = "#{offence["ruleNames"][0]}/#{offence["ruleNames"][1]} #{offence["ruleDescription"]} #{offence["errorDetail"]}"

  message
end
run_stylelint(patch) click to toggle source
# File lib/pronto/markdownlint.rb, line 45
def run_stylelint(patch)
  escaped_file_path = Shellwords.escape(patch.new_file_full_path.to_s)
  `PATH=$(npm bin):$PATH markdownlint-cli2 #{escaped_file_path}`

  JSON.parse(File.read("./markdownlint-results.json"))
end
style_file?(file_path) click to toggle source
# File lib/pronto/markdownlint.rb, line 19
def style_file?(file_path)
  /\.md$/ =~ file_path.to_s
end