Skip to content

Instantly share code, notes, and snippets.

@arcanis
Last active August 29, 2015 14:06
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 arcanis/d11cc72f91fbaab97b1b to your computer and use it in GitHub Desktop.
Save arcanis/d11cc72f91fbaab97b1b to your computer and use it in GitHub Desktop.
Linting Moumoute
#!/usr/bin/env bash
result=0
cd "$(git rev-parse --show-toplevel)"
# Stash the current changes, so that we preserve them
git stash -q --keep-index
# Get the list of changed files from the index
update_list=$(git diff --name-only --staged)
# We only have interest in py/js/scss files
py_files=$(grep '\.py$' <<< "${update_list}")
js_files=$(grep '\.js$' <<< "${update_list}")
scss_files=$(grep '\.scss$' <<< "${update_list}")
# Check the JS files
if [[ ${js_files} != "" ]]; then
xargs js-beautify -qr <<< "${js_files}"
if [[ $(git diff --name-only) != "" ]]; then
[[ ${result} -ne 0 ]] && echo
result=1
echo '[JS] Some files seem to not be conforming to the coding style (JSBeautify).'
echo
git diff -U0
fi
fi
# Check the JS files (again :)
if [[ ${js_files} != "" ]]; then
lint_errors=$(xargs jshint <<< "${js_files}" | grep :)
if [[ ${lint_errors} != "" ]]; then
[[ ${result} -ne 0 ]] && echo
result=1
echo '[JS] Some files seem to not be conforming to the coding style (JSHint).'
echo
cat <<< "${lint_errors}"
fi
fi
# Check the SCSS files
if [[ ${scss_files} != "" ]]; then
lint_errors=$(xargs scss-lint <<< "${scss_files}")
if [[ ${lint_errors} != "" ]]; then
[[ ${result} -ne 0 ]] && echo
result=1
echo '[SCSS] Some files seem to not be conforming to the coding style (SCSS-Lint).'
echo
cat <<< "${lint_errors}"
fi
fi
# Check the Python files
if [[ ${py_files} != "" ]]; then
lint_errors=$(xargs flake8 <<< "${py_files}")
if [[ ${lint_errors} != "" ]]; then
[[ ${result} -ne 0 ]] && echo
result=1
echo '[PY] Some files seem to not be conforming to the coding style (Flake8).'
echo
cat <<< "${lint_errors}"
fi
fi
# Drop the temporary modifications, and restore the stash
git reset -q --hard
git stash pop -q --index
exit ${result}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment