Skip to content

Instantly share code, notes, and snippets.

@ErikDeBruijn
Created March 12, 2020 07:28
Show Gist options
  • Save ErikDeBruijn/69667bd49274f75852306f592f3a6bf4 to your computer and use it in GitHub Desktop.
Save ErikDeBruijn/69667bd49274f75852306f592f3a6bf4 to your computer and use it in GitHub Desktop.
#!/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