4 ms·
I use this as a pre-commit hook with a similar feature to only test changed files: #!/usr/bin/env ruby changed_files = `git diff --name-only --cac
by lamontcg 4y ago
I use this as a pre-commit hook with a similar feature to only test changed files:
#!/usr/bin/env ruby
changed_files = `git diff --name-only --cached`.split.select { |f| File.extname(f) == ".rb" && File.exist?(f) }
unless changed_files.empty?
system "rubocop #{changed_files.join(" ")}"
unless $?.success?
puts "\n\nthere was a rubocop error, please fix before commiting:"
puts "(rubocop -a may be able to autofix these issues for you)\n\n"
end
end
exit $?.to_s[-1].to_i
I tried running it out of the editor but that annoyed me a lot (slow hangs and would change things in the editor as you type which is super annoying to me). Also tried having it autofix but every now and then rubocop would break something which was incredibly annoying.
Can use `git commit --no-verify` to omit the pre-commit hook if it is ever necessary to bypass it.