Sha256: 470ccf9a58d05c1f998dda235594d0b6003f55ebb229cf223ed9cd03690889c9

Contents?: true

Size: 848 Bytes

Versions: 8

Compression:

Stored size: 848 Bytes

Contents

# frozen_string_literal: true

module Overcommit::Hook::Shared
  # Shared code used by all Pronto hooks. Runs pronto linters.

  # @see https://github.com/prontolabs/pronto
  module Pronto
    MESSAGE_TYPE_CATEGORIZER = lambda do |type|
      type.include?('E') ? :error : :warning
    end

    MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+) (?<type>[^ ]+)/.freeze

    def run
      result = execute(command)
      return :pass if result.success?

      # e.g. runtime errors
      generic_errors = extract_messages(
        result.stderr.split("\n"),
        /^(?<type>[a-z]+)/i
      )

      pronto_infractions = extract_messages(
        result.stdout.split("\n").select { |line| line.match?(MESSAGE_REGEX) },
        MESSAGE_REGEX,
        MESSAGE_TYPE_CATEGORIZER,
      )

      generic_errors + pronto_infractions
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
overcommit-0.64.1 lib/overcommit/hook/shared/pronto.rb
overcommit-0.64.0 lib/overcommit/hook/shared/pronto.rb
overcommit-0.63.0 lib/overcommit/hook/shared/pronto.rb
overcommit-0.62.0 lib/overcommit/hook/shared/pronto.rb
overcommit-0.61.0 lib/overcommit/hook/shared/pronto.rb
overcommit-0.60.0 lib/overcommit/hook/shared/pronto.rb
overcommit-0.59.1 lib/overcommit/hook/shared/pronto.rb
overcommit-0.59.0 lib/overcommit/hook/shared/pronto.rb