OCLint 静态代码分析

2017-06-16  本文已影响302人  manajay

环境

脚本 关键点


compilation_db.json
设置-max-priority-1 -max-priority-2 -max-priority-3的值, 提高上限,

例:oclint-json-compilation-database -- -max-priority-1 10000 -max-priority-2 10000 -max-priority-3 10000 -rc LONG_LINE=150 -report-type pmd -o oclint.xml

脚本的全文

#! /bin/sh
#或者source ~/.bash_profile
source /etc/profile

if which oclint 2>/dev/null; then
echo 'oclint exist'
else
brew tap oclint/formulae
brew install oclint
fi
if which xcpretty 2>/dev/null; then
echo 'xcpretty exist'
else
gem install xcpretty
fi

# workspace 和 target 只能使用一种. 
#myworkspace=XXX.xcworkspace # 替换workspace的名字
#myscheme=XXX # 替换scheme的名字

targetname=HttpManager
myscheme=HttpManager

xcodebuild -target $targetname -scheme $myscheme clean&&
xcodebuild -target $targetname -scheme $myscheme \
-configuration Debug \
| xcpretty -r json-compilation-database

cp ./build/reports/compilation_db.json ./compile_commands.json

if [ -f ./compile_commands.json ]; then echo "compile_commands.json 文件存在";
else echo "-----compile_commands.json文件不存在-----"; fi

oclint-json-compilation-database  -- \
-report-type html -o oclint_result.html \
-rc LONG_LINE=200 \
-rc=NCSS_METHOD=100 \
-max-priority-1=100000 \
-max-priority-2=100000 \
-max-priority-3=100000; \
rm compile_commands.json;
if [ -f ./oclint_result.html ]; then echo '-----分析完毕-----'
else echo "-----分析失败-----"; fi

结果

oclint-report.png 结果-01.png 结果-02.png
#! /bin/sh
#或者source ~/.bash_profile
source /etc/profile
cd ${SRCROOT}

if which oclint 2>/dev/null; then
echo 'oclint exist'
else
brew tap oclint/formulae
brew install oclint
fi
if which xcpretty 2>/dev/null; then
echo 'xcpretty exist'
else
gem install xcpretty
fi

xcodebuild  clean&&
xcodebuild | xcpretty -r json-compilation-database

cp ./build/reports/compilation_db.json ./compile_commands.json

if [ -f ./compile_commands.json ]; then echo "compile_commands.json 文件存在";
else echo "-----compile_commands.json文件不存在-----"; fi


oclint-json-compilation-database  -- \
-report-type xcode \
-rc LONG_LINE=200 \
-rc=NCSS_METHOD=100 \
-max-priority-1=100000 \
-max-priority-2=100000 \
-max-priority-3=100000; \
rm compile_commands.json;

问题

相关链接


OCLint 安装与使用
iOS使用OCLint做静态代码分析

关于OCLint自定义规则
使用 oclint + Jenkins 进行自动化 Code Review


iOS Infer 静态代码分析

上一篇下一篇

猜你喜欢

热点阅读