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