Sha256: 17ddb6c62762e1e89e6f3f58b9d65731cd0c6f40a2c179e280e6067288744763

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'pronto/swiftlint/wrapper'
require 'pronto'

module Pronto
  class SwiftlintRunner < Runner
    def run
      return [] unless @patches

      offences = Swiftlint::Wrapper.new.lint

      @patches.select { |p| p.additions > 0 }
        .select { |p| swift_file?(p.new_file_full_path) }
        .map { |p| inspect(p, offences) }
        .flatten
        .compact
    end

    private

    def inspect(patch, offences)
      messages = []
      offences_in_file = offences[patch.new_file_full_path.to_s]
      return unless offences_in_file

      offences_in_file.each do |offence|
        messages += patch
          .added_lines
          .select { |line| line.new_lineno == offence[:line] }
          .map { |line| new_message(offence, line) }
      end

      messages.compact
    end

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

    def swift_file?(path)
      %w(.swift).include?(File.extname(path))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pronto-swiftlint-0.2.0 lib/pronto/swiftlint_runner.rb