Created
March 12, 2020 07:28
-
-
Save ErikDeBruijn/69667bd49274f75852306f592f3a6bf4 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env bash | |
set -eu | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[0;33m' | |
NO_COLOR='\033[0m' | |
CLEAR_LINE='\r\033[K' | |
printf "๐ Attempting auto-correct with Rubocop..." | |
cd StekkerWeb | |
if ! command -v bin/rubocop > /dev/null; then | |
printf "${CLEAR_LINE}๐${RED} Install Rubocop and be sure it is available on your PATH${NO_COLOR}\n" | |
printf "โน๏ธ Try 'gem install rubocop'\n" | |
exit -1 | |
fi | |
#suspects="$(comm -12 <(git diff --cached --name-only --diff-filter=AMC | sort) <(rubocop --list-target-files | sort) | tr '\n' ' ')" | |
changed_files="$(git diff --name-only --diff-filter=AMC)" | |
rubocop --auto-correct ${changed_files/StekkerWeb\//./} | |
printf "๐ Checking with Rubocop if we're good..." | |
suspects="$(rubocop ${changed_files/StekkerWeb\//./})" | |
exit $? | |
suspects="$suspects | tr '\n' ' '" | |
if [ -n "$suspects" ]; then | |
printf "${CLEAR_LINE}๐ Linting files: ${suspects}" | |
# Run rubocop on the staged files | |
if ! bin/rubocop --parallel --format simple ${suspects} > /dev/null | |
then | |
printf "${CLEAR_LINE}${RED}๐ Rubocop found some issues. Fix, stage, and commit again${NO_COLOR}\n" | |
printf "โน๏ธ Try 'bin/rubocop --display-cop-names --extra-details --auto-correct && git add -p'\n" | |
exit -1 | |
fi | |
fi | |
printf "${CLEAR_LINE}๐${GREEN} Rubocop is appeased.${NO_COLOR}\n" | |
exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment