Last active
October 19, 2021 08:06
-
-
Save pch/c5481a30df1501953651f8b655372129 to your computer and use it in GitHub Desktop.
pre-commit
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
#!/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