Skip to content

Instantly share code, notes, and snippets.

@a-square
Created January 21, 2015 10:48
Show Gist options
  • Save a-square/ae97a932855375c9b2bd to your computer and use it in GitHub Desktop.
Save a-square/ae97a932855375c9b2bd to your computer and use it in GitHub Desktop.
A modern CocoaPods-aware OCLint target script for Xcode
#
# parameters (including heuristic defaults)
#
if [ -z ${MY_SCHEME+x} ]
then
export MY_SCHEME=${PROJECT_NAME}
fi
if [ -z ${MY_WORKSPACE+x} ]
then
export MY_WORKSPACE=${PROJECT_NAME}.xcworkspace
fi
#
# preparation
#
# loading Bash parameters
source ~/.bash_profile
# adding local bin to the path manually, because sometimes it is omitted in the profile
export PATH=/usr/local/bin:${PATH}
# changing to the source root directory
cd ${SOURCE_ROOT}
# checking that we have all the necessary tools
if ! which -s xctool
then
echo 'error: xctool not found, install e.g. with homebrew'
fi
if ! which -s oclint-json-compilation-database
then
echo 'error: OCLint not installed, install e.g. the binary package from the web site'
fi
#
# actions
#
# cleaning up before building
rm -f compile_commands.json
xctool -workspace ${MY_WORKSPACE} -scheme ${MY_SCHEME} clean > /dev/null
# building and analyzing
xctool -workspace ${MY_WORKSPACE} -scheme ${MY_SCHEME} -reporter json-compilation-database:compile_commands.json build
oclint-json-compilation-database -e Pods -- -max-priority-1=100000 -max-priority-2=100000 -max-priority-3=100000 -disable-rule=LongLine -disable-rule=UselessParentheses -disable-rule=IvarAssignmentOutsideAccessorsOrInit | sed 's/\(.*\.\m\{1,2\}:[0-9]*:[0-9]*:\)/\1 warning:/'
# second clean-up to avoid adding too much stuff to .gitignore
rm -f compile_commands.json
xctool -workspace ${MY_WORKSPACE} -scheme ${MY_SCHEME} clean > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment