#!/bin/sh

pass=true
RED='\033[1;31m'
GREEN='\033[0;32m'
NC='\033[0m'

echo "Running Linters:"

# Run rubocop and get the output and return code
rubocop=$(git status | grep -v deleted | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs bundle exec rubocop --parallel --force-exclusion --format simple ${suspects})
return_code=$?

if [ $return_code != 0 ]; then
  echo "$rubocop\n"
  printf "\n${RED}Rubocop failed, please fix and then re-commit${NC}\n"
  pass=false
else
  printf "${GREEN}Rubocop passed.${NC}\n"
fi

# Run reek and get the output and return code
reek=$(git status | grep -v deleted | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs bundle exec bundle exec reek --force-exclusion)
return_code=$?

if [ $return_code != 0 ]; then
  echo "$reek\n"
  printf "\n${RED}Reek failed, please fix and then re-commit.${NC}\n"
  pass=false
else
  printf "${GREEN}Reek passed.${NC}\n"
fi

# If you reach this point, everything was cool and means you are a good player
if $pass; then
  exit 0
fi

exit 1