Sha256: 300aa56ba94541792ca7ffd2a72716663794b3af57f9dbe3eb30b79a78f2cb08

Contents?: true

Size: 922 Bytes

Versions: 3

Compression:

Stored size: 922 Bytes

Contents

require 'pronto'
require 'haml_lint'

module Pronto
  class Haml < Runner
    def initialize(_, _ = nil)
      super

      @runner = ::HamlLint::Runner.new
    end

    def run
      return [] unless @patches

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

    def inspect(patch)
      lints = @runner.run(files: [patch.new_file_full_path.to_s]).lints
      lints.map do |lint|
        patch.added_lines.select { |line| line.new_lineno == lint.line }
          .map { |line| new_message(lint, line) }
      end
    end

    def new_message(lint, line)
      path = line.patch.delta.new_file[:path]
      Message.new(path, line, lint.severity, lint.message, nil, self.class)
    end

    private

    def haml_file?(path)
      File.extname(path) == '.haml'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pronto-haml-0.8.0 lib/pronto/haml.rb
pronto-haml-0.7.0 lib/pronto/haml.rb
pronto-haml-0.6.0 lib/pronto/haml.rb