Sha256: bba2cab2f218352ba003bc6f84a0dd50294a2ec78aa20140836e2cd04f5a9494

Contents?: true

Size: 1.38 KB

Versions: 158

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

158 entries across 158 versions & 2 rubygems

Version Path
punchlist-1.3.2 .git-hooks/pre_commit/punchlist.rb
punchlist-1.3.1 .git-hooks/pre_commit/punchlist.rb
checkoff-0.201.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.200.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.199.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.198.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.197.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.196.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.195.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.194.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.193.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.192.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.191.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.190.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.189.0 .git-hooks/pre_commit/punchlist.rb
checkoff-0.188.0 .git-hooks/pre_commit/punchlist.rb
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