Skip to content

Instantly share code, notes, and snippets.

@tobiashm
Created September 30, 2016 07:24
Show Gist options
  • Save tobiashm/0ff8533f8c36f65c206b1c304c1e4833 to your computer and use it in GitHub Desktop.
Save tobiashm/0ff8533f8c36f65c206b1c304c1e4833 to your computer and use it in GitHub Desktop.
Git pre-commit hook
#!/bin/bash -l
# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
[[ -f ".ruby-version" ]] && rvm use . > /dev/null
if [ -f ".rubocop.yml" ]; then
changed_ruby_files=$(git diff --cached --name-only --diff-filter=ACM | grep -e '\.rb$' | grep -v 'db/schema' | grep -v 'db/migrate')
if [ "$changed_ruby_files" != "" ]; then
bundle exec rubocop -n $changed_ruby_files || exit 1
fi
fi
if [ -f ".scss-lint.yml" ]; then
changed_scss_files=$(git diff --cached --name-only --diff-filter=ACM | grep -e '\.scss$' | grep -v 'vendor/')
if [ "$changed_scss_files" != "" ]; then
bundle exec scss-lint $changed_scss_files || exit 1
fi
fi
if [ -f "package.json" ]; then
# changed_js_files=$(git diff --cached --name-only --diff-filter=ACM | grep -e '\.js(\.erb)?$' | grep -v 'vendor/')
npm run lint || exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment