Sha256: a688639697b1e4691f917178c511f5d51c4063f042f603b566342f12de80b156

Contents?: true

Size: 890 Bytes

Versions: 6

Compression:

Stored size: 890 Bytes

Contents

require 'pronto'
require 'haml_lint'

module Pronto
  class Haml < Runner
    def initialize
      @runner = ::HamlLint::Runner.new
    end

    def run(patches, _)
      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)
    end

    private

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pronto-haml-0.5.1 lib/pronto/haml.rb
pronto-haml-0.5.0 lib/pronto/haml.rb
pronto-haml-0.4.4 lib/pronto/haml.rb
pronto-haml-0.4.3 lib/pronto/haml.rb
pronto-haml-0.4.2 lib/pronto/haml.rb
pronto-haml-0.4.1 lib/pronto/haml.rb