一、OCLint
OCLint is a static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code and looking for potential problems。
OCLint是一个静态代码分析工具,通过检查C,C ++和Objective-C代码,寻找潜在问题来提高质量并减少缺陷。
二、安装
1、安装xcpretty
sudo gem install xcpretty
2、安装OCLint
brew tap oclint/formulae
brew install oclint
Tips:
需要gem和Homebrew,请自行安装。
三、使用
1、脚本
xcodebuild clean
xcodebuild archive -workspace yourProject.xcworkspace -scheme yourProject | tee xcodebuild.log | xcpretty -r json-compilation-database -o compile_commands.json
oclint-json-compilation-database -e Pods -- \
-max-priority-1=100000 \
-max-priority-2=100000 -max-priority-3=100000 \
-disable-rule=InvertedLogic \
-disable-rule=CollapsibleIfStatements \
-disable-rule=UnusedMethodParameter \
-disable-rule=LongVariableName \
-disable-rule=ShortVariableName \
-disable-rule=UselessParentheses \
-disable-rule=IvarAssignmentOutsideAccessorsOrInit | sed 's/\(.*\.\m\{1,2\}:[0-9]*:[0-9]*:\)/\1 warning:/'
Tips:
xcodebuild archive改为build或者analyze,json-compilation-database为空,不知原因。
tee xcodebuild.log不是必要操作,可去除。
2、规则
过滤规则可以自定义,也可以使用官网定义过的规则。
官方文档
3、持续集成
可将OClint集成至Jenkins。此处不赘述。
摘要
http://oclint.org
http://www.cocoachina.com/ios/20170928/20669.html
http://docs.oclint.org/en/stable/guide/xcpretty.html
http://docs.oclint.org/en/stable/rules/index.html
https://stackoverflow.com/questions/31447296/oclint-compile-commands-json-not-found-at-current-location/31449152
https://blog.csdn.net/liqinghuiyx/article/details/52414975