class Danger::DangerOrmolu

Lint haskell files against ormolu formatting

@example Ensure the files are correctly formatted

ormolu.check files

@see blackheaven/danger-ormolu @tags haskell, formatting, ormolu

Public Instance Methods

check(files) click to toggle source

Check that the files are correctly formatted @param files [Array<String>] @return [void]

# File lib/ormolu/plugin.rb, line 18
def check(files)
  files
    .each do |file|
      result = `ormolu --mode stdout --check-idempotence "#{file}" | diff "#{file}" -`
      next if result.empty?

      extract_diffs(result.lines)
        .each do |diff|
          inconsistence(file, diff[:line], diff[:diff])
        end
    end
end

Private Instance Methods

extract_diffs(lines) click to toggle source
# File lib/ormolu/plugin.rb, line 38
def extract_diffs(lines)
  lines
    .reverse
    .slice_when { |l| l =~ /^\d.*/ }
    .to_a
    .map(&:reverse)
    .reverse
    .map do |chunk|
      { line: chunk.first[/^\d+/].to_i, diff: chunk.flatten }
    end
end
inconsistence(file, line, diff) click to toggle source
# File lib/ormolu/plugin.rb, line 33
def inconsistence(file, line, diff)
  message = "Style error, fix it through \n\n```haskell\n#{diff}\n``` \n"
  warn(message, file: file, line: line)
end