invoke at git repository root
$ curl -o - https://gist.githubusercontent.com/fukajun/03a7635d34dc0acd8ab95855fbb73942/raw/install.sh | bash
| curl https://gist.githubusercontent.com/fukajun/03a7635d34dc0acd8ab95855fbb73942/raw/pre-commit -o - > .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit |
| #!/usr/bin/env ruby | |
| def check | |
| is_valid = true | |
| check_target_files = `git diff-index --name-status HEAD | cut -c3-`.split("\n") | |
| invalid_results = [] | |
| check_target_files.each do |file_path| | |
| line_no = 1 | |
| begin | |
| file = open(file_path) | |
| file.readlines.each do |line| | |
| if line.match(/\u3000/) | |
| is_valid = false | |
| invalid_results << "file_path:#{file_path} line:#{line_no} reason:zenkaku-space code:\"#{line.sub(/\n$/, '')}\"" | |
| end | |
| line_no += 1 | |
| end | |
| ensure | |
| file.close if file | |
| end | |
| end | |
| if invalid_results.size >= 1 | |
| puts '--------------------------------------' | |
| puts 'This commit is including invalid line.' | |
| puts '--------------------------------------' | |
| puts "#{invalid_results.join("\n")}" | |
| puts '--------------------------------------' | |
| end | |
| is_valid | |
| end | |
| invalid_exit_code = ENV['IGNORE_PRE_COMMIT_CHECK'] ? 0 : 1 | |
| exit(check ? 0 : invalid_exit_code) | |