iOS代碼檢測入坑記事
我接觸的代碼檢測
- OCLint + xcpretty
- sonar
- infer
infer
具體使用
infer -- xcodebuild -target <target name> -configuration <build configuration> -sdk iphonesimulator
例如:
#分析之前先把之前的build緩存清理下
xcodebuild -workspace HIGHTONG_Public.xcworkspace -scheme HIGHTONG_Jktv -configuration Debug -sdk iphoneos11.0
#根據(jù)自己醒目名字使用infer 命令進行分析
infer -- xcodebuild -workspace HIGHTONG_Public.xcworkspace -scheme HIGHTONG_Jktv -configuration Debug -sdk iphoneos11.0
infer的優(yōu)勢
- 安裝過程簡潔,不需要過多的配置(前提是電腦之前安裝過Homebrow)
- 使用方便,只需要一行命令
sonar
Sonar 是一個用于代碼質(zhì)量管理的開放平臺。通過插件機制,Sonar 可以集成不同的測試工具,代碼分析工具,以及持續(xù)集成工具。相比于Jenkins ,sonar更關注代碼的變化,通過量化的方式度量代碼變化。
如果不需要持續(xù)集成,sonar只需要兩個配置文件就可以進行代碼的靜態(tài)檢測。
- 安裝:
brew install sonar - 配置文件修改
run-sonar.shsonar-project.properties - 執(zhí)行run-sonar.sh腳本,檢測代碼
資源下載
* [run-sonar.sh](https://raw.githubusercontent.com/octo-technology/sonar-objective-c/master/src/main/shell/run-sonar.sh)
* [sonar-project.properties](https://raw.githubusercontent.com/octo-technology/sonar-objective-c/master/sample/sonar-project.properties)
參考資源
* [IOS-Sonar代碼質(zhì)量監(jiān)控](http://www.itdecent.cn/p/f58e89573d33)
* [[實踐]Sonar Xcode8兼容](https://my.oschina.net/ChenTF/blog/806565)
* [iOS Sonar集成流程詳解](http://www.itdecent.cn/p/74bee59fef1c)
* [基于Sonar的iOS代碼質(zhì)量檢測系統(tǒng)](http://www.itdecent.cn/p/6b61783b9a38)
* [IOS測試之sonar檢查ios代碼質(zhì)量](http://blog.csdn.net/itfootball/article/details/45058591)
OCLint + xcpretty
- 安裝xcpretty
sudo gem install xcpretty
- 安裝OCLint
brew tap oclint/formulae brew install oclint - 根目錄下 運行腳本:
#清理
xcodebuild clean
#生成JSON文件 用于分析
xcodebuild -workspace demo.xcworkspace -scheme demo -configuration Debug \
| tee xcodebuild.log \
| xcpretty -r json-compilation-database -o compile_commands.json
#OCLint 分析(根據(jù)一定規(guī)則進行分析)
oclint-json-compilation-database -v \
-e Pods \
-e MGLivenessDetection \
-e MGBaseKit \
-e MGIDCard \
oclint_args -- -report-type html -o oclintReport.html \
-disable-rule ObjCAssignIvarOutsideAccessors \
-disable-rule ShortVariableName \
-rc=MINIMUM_CASES_IN_SWITCH=3 \
-rc=CYCLOMATIC_COMPLEXITY=10 \
-rc=LONG_CLASS=700 \
-rc=LONG_LINE=200 \
-rc=NCSS_METHOD=40 \
-rc=NESTED_BLOCK_DEPTH=5 \
-rc=TOO_MANY_FIELDS=20 \
-rc=TOO_MANY_METHODS=30 \
-rc=TOO_MANY_PARAMETERS=6
# oclint_args -- -report-type xcode \
高級用法,代碼檢測規(guī)則: