Skip to content

Instantly share code, notes, and snippets.

@adriangl
Created November 23, 2016 13:28
Show Gist options
  • Save adriangl/689efa25cc6024f08517c40cbf83e260 to your computer and use it in GitHub Desktop.
Save adriangl/689efa25cc6024f08517c40cbf83e260 to your computer and use it in GitHub Desktop.
Git pre-commit script for running Checkstyle in all Android-Studio based project files
#!/bin/sh
#Define paths where the checkstyle file is and where to check for style inconsistencies
CHECKSTYLE_PATH="checkstyle.xml"
CHECKSTYLE_FOLDERS_TO_CHECK="app/src/main/java app/src/androidTest/java app/src/test/java"
#Check if the 'checkstyle' command is installed
#Magic: http://stackoverflow.com/a/677212
command -v checkstyle >/dev/null 2>&1 || { echo >&2 "checkstyle is not installed, aborting.\nInstall it using brew or apt-get"; exit 1; }
#Run checkstyle over our files
checkstyle -c $CHECKSTYLE_PATH $CHECKSTYLE_FOLDERS_TO_CHECK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment