Forked from timheilman/rubocop_pre_commit_hook
Last active
September 1, 2017 21:50
-
-
Save SamGerber-zz/12394cf8a0b6bfed9dc4177978ba78d8 to your computer and use it in GitHub Desktop.
Ruby style guide git pre-commit hook using Rubocop as the style guide checker. Only runs on staged ruby files that have been added and/or modified. Itself passes rubocop with default settings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Source: https://gist.github.com/timheilman/1bb8da91be4b79425d67314c9ae23f6b | |
# credit to https://www.github.com/joneshf | |
require 'rubocop' | |
changed_files = | |
`git diff --name-only --cached -- '*.rb' '*.rake'` | |
.split("\n").join(' ') | |
system("rubocop '#{changed_files}'") unless changed_files.empty? | |
exit $CHILD_STATUS.to_s[-1].to_i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment