Skip to content

Instantly share code, notes, and snippets.

@tobiashm
Created October 8, 2014 07:14
Show Gist options
  • Select an option

  • Save tobiashm/21edd17d0b96795dcdf9 to your computer and use it in GitHub Desktop.

Select an option

Save tobiashm/21edd17d0b96795dcdf9 to your computer and use it in GitHub Desktop.
Run RuboCop and NPM check on `git commit`
#!/bin/bash
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
if [ -f ".rubocop.yml" ]; then
changed_ruby_files=$(git diff --cached --name-only --diff-filter=ACM | grep -e '\.rb$' | grep -v 'db/schema')
if [ "$changed_ruby_files" != "" ]; then
cd . # Cause RVM to change Ruby version to the one specified in the Gemfile or .ruby-version
bundle exec rubocop -n $changed_ruby_files || exit 1
fi
fi
PATH=/usr/local/bin:$PATH
if [ -f "package.json" ]; then
npm install 1>&2
npm run check || exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment