Skip to content

Instantly share code, notes, and snippets.

@guilhermearaujo
Last active July 27, 2022 09:36
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save guilhermearaujo/a6e4dbb982fea40a0513 to your computer and use it in GitHub Desktop.
Save guilhermearaujo/a6e4dbb982fea40a0513 to your computer and use it in GitHub Desktop.
OCLint integration with Xcode

OCLint integration with Xcode

1. Integration

  • Add a new Target of kind Aggregate, name it OCLint
  • Under Builde Phases, add a new Run Script Phase
  • Paste the script

2. Usage

  • Select target OCLint
  • Build the target (press +B)
  • Wait for the script to run
  • Warnings will appear in the Issue Navigator (press +4)

3. Customization

  • Rules can be ignored by adding the parameter -disable-rule=<RuleName> to the oclint-json-compilation-database command
  • A comprehensive list of rules can be found at OCLint documentation
source ~/.bash_profile
export PATH=$PATH:/usr/local/bin/
if [ -z "${SCHEME+x}" ]
then
export SCHEME="${PROJECT_NAME}"
fi
if [ -z "${WORKSPACE+x}" ]
then
export WORKSPACE="${PROJECT_NAME}.xcworkspace"
fi
cd "${SOURCE_ROOT}"
# Check if xctool and oclint are installed
if ! which -s xctool
then
echo 'error: xctool not found, install e.g. with homebrew'
exit 1
fi
if ! which -s oclint-json-compilation-database
then
echo 'error: OCLint not installed, install e.g. with homebrew cask'
exit 2
fi
# Cleanup before building
rm -f compile_commands.json
xctool -workspace "${WORKSPACE}" -scheme "${SCHEME}" clean > /dev/null
# Build and analyze
# OCLint Rule Index: http://docs.oclint.org/en/dev/rules/index.html
xctool -workspace "${WORKSPACE}" -scheme "${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=InvertedLogic \
-disable-rule=UnusedMethodParameter \
-disable-rule=LongLine \
-disable-rule=LongVariableName \
-disable-rule=ShortVariableName \
-disable-rule=UselessParentheses \
-disable-rule=IvarAssignmentOutsideAccessorsOrInit | sed 's/\(.*\.\m\{1,2\}:[0-9]*:[0-9]*:\)/\1 warning:/'
# Final cleanup
rm -f compile_commands.json
@Aanchaljain9988
Copy link

This script was not working.I was getting error : LLVM Error - Couldn't read JSON compilation Database error.
But now i have resolved by replacing with other script.

Was something missing with documentation ?

@dance-cmdr
Copy link

It built for me when I installed Xctool but it doesn't emit any issues

@masters3d
Copy link

Thank you this was helpful to get it working on travis -max-priority-1=100000 -max-priority-2=100000 -max-priority-3=100000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment