Sha256: e2244a596a97bfca0e79d613fa03a73d9da45b081023d1e3130312d46930d2cc

Contents?: true

Size: 1001 Bytes

Versions: 27

Compression:

Stored size: 1001 Bytes

Contents

#!/usr/bin/env ruby
require 'colorize'

def switch_dir
  if File.directory?('.git')
    return
  end

  Dir.chdir '..'
  switch_dir
end

begin
  stage = `git diff --cached --name-only`.strip
  if stage == ''
    exit 0
  end

  @pass = true

  files = stage.split("\n")

  count = 0

  files.each do |file|
    if File.extname(file) == '.java'

      current_path = Dir.pwd
      switch_dir

      result = `java -jar #{Dir.pwd}/_script/checkstyle-7.0.jar -c #{Dir.pwd}/_script/checkstyle.xml #{Dir.pwd}/#{file}`
      result = result.gsub("Starting audit...\n", '')
      result = result.gsub("Audit done.\n", '')
      result = result.force_encoding('UTF-8')

      if result.include?('WARN') || result.include?('ERROR')
        count = count + 1
        puts "#{count}、 #{result}\n".red
        @pass = false
      elsif result.strip != ''
        puts result
      end

      Dir.chdir current_path
    end
  end

  unless @pass
    exit 1
  end
rescue => e
  puts "error: #{e}".red
  exit 1
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
dngg-1.0.1 lib/dngg/hook/pre-commit
dngg-1.0.0 lib/dngg/hook/pre-commit
dngg-0.1.0 lib/dngg/hook/pre-commit
dngg-0.0.9 lib/dngg/hook/pre-commit
dngg-0.0.8 lib/dngg/hook/pre-commit
dngg-0.0.7 lib/dngg/hook/pre-commit
dngg-0.0.6 lib/dngg/hook/pre-commit
dngg-0.0.5 lib/dngg/hook/pre-commit
dngg-0.0.4 lib/dngg/hook/pre-commit
dngg-0.0.3 lib/dngg/hook/pre-commit
dngg-0.0.2 lib/dngg/hook/pre-commit
dngg-0.0.1 lib/dngg/hook/pre-commit
ggsm-1.9.6 lib/ggsm/hook/pre-commit
ggsm-1.9.5 lib/ggsm/hook/pre-commit
ggsm-1.9.4 lib/ggsm/hook/pre-commit
ggsm-1.9.3 lib/ggsm/hook/pre-commit
ggsm-1.9.2 lib/ggsm/hook/pre-commit
ggsm-1.9.1 lib/ggsm/hook/pre-commit
ggsm-1.9.0 lib/ggsm/hook/pre-commit
ggsm-1.8.6 lib/ggsm/hook/pre-commit