工具 - 使用 OCLint 进行静态代码分析
变更记录
序号 | 录入时间 | 录入人 | 备注 |
---|---|---|---|
1 | 2017-04-08 | Alfred Jiang | - |
方案名称
工具 - 使用 OCLint 进行静态代码分析
关键字
工具 \ 静态代码分析
需求场景
- 需要对 Objective-C 代码进行静态代码分析时
参考链接
详细内容
针对 Objective-C 语言的静态代码分析,主要有以下两种方式:
1. 使用 Xcode 的 Analyze (shift + command + B)进行静态代码分析
2. 使用 OCLint 工具
安装
(1) 安装 oclint
通过 Homebrew 安装 oclint
1 | brew tap oclint/formulae |
也可以通过源码安装 或 release 包进行 oclint 安装
(2) 安装 xcpretty
1 | gem install xcpretty |
升级
1 | brew update |
使用
(1) 清理工程
1 | xcodebuild clean |
(2) 编译并输出数据
1 | xcodebuild | xcpretty -r json-compilation-database |
(3) 导出分析数据
1 | cp build/reports/compilation_db.json compile_commands.json |
(4) 使用 oclint 进行分析导出
1 | oclint-json-compilation-database -e Pods -- -rc=LONG_LINE=200 -rc=NCSS_METHOD=100 -o=report.html |
关于 OCLint 规则与结果分析可以参考这里
使用以下 shell 脚本进行一键操作(将该脚本置于与 .xcodeproj 同级目录)
1 | ! /bin/sh |
效果图
(无)
备注
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 宁静至远,博雅多通!