Sha256: 1c4fe260f7ecc084e16b13ade10c7da1d6144823deaa7ad26ab4dfe641c09d47

Contents?: true

Size: 647 Bytes

Versions: 18

Compression:

Stored size: 647 Bytes

Contents

require 'pre-commit/checks/plugin'

module PreCommit
  module Checks
    class Go < Plugin

      def call(staged_files)
        staged_files = staged_files.grep(/\.go$/)
        return if staged_files.empty?

        errors = staged_files.map { |file| run_check(file) }.compact
        return if errors.empty?

        errors.join("\n")
      end

      def run_check(file)
        cmd = "gofmt -l #{file} 2>&1"
        result = %x[ #{cmd} ]
        cmd = "go build -o /dev/null #{file} 2>&1"
        result << %x[ #{cmd} ]
      end

      def self.description
        "Detects bad Go formatting and compiler errors"
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
pre-commit-0.26.0 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.25.0 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.24.0 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.23.0 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.22.1 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.22.0 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.21.0 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.20.0 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.19.0 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.18.0 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.17.0 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.16.3 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.16.2 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.16.1 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.16.0 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.15.0 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.14.1 lib/plugins/pre_commit/checks/go.rb
pre-commit-0.14.0 lib/plugins/pre_commit/checks/go.rb