Skip to content

Instantly share code, notes, and snippets.

@pch
Last active October 19, 2021 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pch/c5481a30df1501953651f8b655372129 to your computer and use it in GitHub Desktop.
Save pch/c5481a30df1501953651f8b655372129 to your computer and use it in GitHub Desktop.
pre-commit
#!/bin/bash
#
# Example pre-commit hook: triggers rubocop & eslint on staged files.
#
# To use it, create a symlink in your .git/hooks directory:
#
# $ ln -s $(pwd)/bin/pre-commit .git/hooks
set -e
# Ruby
staged_files=$(git diff --cached --name-only --diff-filter=ACM backend/ | grep '.rb')
if [ -n "$staged_files" ]; then
bundle exec rubocop -c .rubocop.yml --auto-correct --fail-level autocorrect $staged_files
fi
# Frontend
staged_files_front=$(git diff --cached --name-only --diff-filter=ACM frontend/ | grep -E '\.ts|\.js')
if [ -n "$staged_files_front" ]; then
yarn eslint --quiet --fix $staged_files_front
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment