Sha256: b83003ac8f6176c411ef42a9991fecdbf94003383c292de55c5665e9fd7b58b0
Contents?: true
Size: 997 Bytes
Versions: 9
Compression:
Stored size: 997 Bytes
Contents
#!/usr/bin/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
9 entries across 9 versions & 1 rubygems