Skip to content

Instantly share code, notes, and snippets.

@hectorddmx
Forked from guilhermearaujo/README.md
Last active September 14, 2018 19:23
Show Gist options
  • Save hectorddmx/49293f7e5720070c248a771730764747 to your computer and use it in GitHub Desktop.
Save hectorddmx/49293f7e5720070c248a771730764747 to your computer and use it in GitHub Desktop.
OCLint integration with Xcode

OCLint (0.13) 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
# Original script at
# https://gist.github.com/guilhermearaujo/a6e4dbb982fea40a0513
##source ~/.bash_profile
export PATH=$PATH:/usr/local/bin/
if [ -z "${SCHEME+x}" ]
then
export SCHEME="${PROJECT_NAME}"
fi
# "Workspace" is actually the project
if [ -z "${WORKSPACE+x}" ]
then
export WORKSPACE="${PROJECT_NAME}.xcodeproj"
fi
cd "${SOURCE_ROOT}"
# Check if oclint is installed
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
# Build and analyze
# OCLint Rule Index: https://oclint-docs.readthedocs.io/en/v0.13/rules/index.html
echo "Starting clean and build..."
xcodebuild -project "${WORKSPACE}" -scheme "${SCHEME}" -configuration Bot \
clean build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO > xcodebuild.log
echo "Finished clean and build project."
oclint-xcodebuild | xcpretty -r json-compilation-database
echo "Built json compilation database at ./compile-commands.json"
# AssignIvarOutsideAccessors is for version 0.13
# IvarAssignmentOutsideAccessorsOrInit is for 0.10.3 only
oclint-json-compilation-database -e Janrain -- -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=HighNcssMethod \
-disable-rule=HighNPathComplexity \
-disable-rule=LongMethod \
-disable-rule=LongClass \
-disable-rule=HighCyclomaticComplexity \
-disable-rule=TooManyMethods \
-disable-rule=DeepNestedBlock \
-disable-rule=AssignIvarOutsideAccessors \
-disable-rule=IvarAssignmentOutsideAccessorsOrInit | sed 's/\(.*\.\m\{1,2\}:[0-9]*:[0-9]*:\)/\1 warning:/'
# Final cleanup
rm -f compile_commands.json
rm -f xcodebuild.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment