Sha256: bba2cab2f218352ba003bc6f84a0dd50294a2ec78aa20140836e2cd04f5a9494

Contents?: true

Size: 1.38 KB

Versions: 162

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require 'overcommit'
require 'overcommit/hook/pre_commit/base'

# Overcommit configuration
module Overcommit
  module Hook
    module PreCommit
      # Runs `punchlist` against any modified Ruby files.
      class Punchlist < Base
        # @param stdout [String]
        # @return [Array<Overcommit::Hook::Message>]
        def parse_output(stdout)
          stdout.split("\n").map do |line|
            # @sg-ignore
            file, line_no, _message = line.split(':', 3)
            Overcommit::Hook::Message.new(:error, file, line_no.to_i, line)
          end
        end

        # @return [String]
        def files_glob
          "{" \
            "#{applicable_files.join(',')}" \
            "}"
        end

        # @return [Symbol, Array<Overcommit::Hook::Message>]
        def run
          # @sg-ignore
          # @type [Overcommit::Subprocess::Result]
          result = execute([*command, '-g', files_glob])

          warn result.stderr

          # If the command exited with a non-zero status or produced any output, treat it as a failure
          if result.status.nonzero? || !result.stdout.empty? || !result.stderr.empty?
            # Parse the output to create Message objects
            stdout = result.stdout
            messages = parse_output(stdout)

            return messages
          end

          :pass
        end
      end
    end
  end
end

Version data entries

162 entries across 162 versions & 2 rubygems

Version Path
checkoff-0.187.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.186.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.185.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.184.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.183.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.182.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.181.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.180.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.179.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.178.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.177.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.176.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.175.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.174.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.173.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.172.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.171.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.170.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.169.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.168.0 .git-hooks/pre_commit/punchlist.rb