Skip to content

Instantly share code, notes, and snippets.

@essmahr
Last active March 23, 2018 20:57
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 essmahr/05f37b0dec779c5d01b9225241e7d208 to your computer and use it in GitHub Desktop.
Save essmahr/05f37b0dec779c5d01b9225241e7d208 to your computer and use it in GitHub Desktop.
Diff-based, filetype-specific linting
#!/usr/bin/env bash
# Run filetype-specific linting on a given commit range.
# ------------------------------------------------------
#
# Usage:
#
# $ travis/validate HEAD~5
# $ travis/validate $TRAVIS_COMMIT_RAGE
changed_files=`git diff --name-only $1 --diff-filter=ACMRTUXB`
for ext in php js scss; do
changed_by_type=`echo "$changed_files" | awk -v ext="$ext$" '{ if($1 ~ ext) print $1}'`
if [[ -z "$changed_by_type" ]]; then
echo "no $ext files found. Skipping..."
continue
fi
case $ext in
php)
echo "Checking PHP..."
vendor/bin/php-validate $changed_by_type
;;
js|scss)
echo "Checking JS & SCSS..."
yarn run prettier:validate $changed_by_type
;;
esac
response=$?
if [[ $response > 0 ]]; then
exit $response
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment