Skip to content

Instantly share code, notes, and snippets.

@SamGerber-zz
Forked from timheilman/rubocop_pre_commit_hook
Last active September 1, 2017 21:50
Show Gist options
  • Save SamGerber-zz/12394cf8a0b6bfed9dc4177978ba78d8 to your computer and use it in GitHub Desktop.
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.
#!/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