天天看点

OC静态代码检查OC静态代码检查

OC静态代码检查

准备阶段

oclint的安装

1.安装Homebrew

2.安装OCLint

brew tap oclint/formulae
brew install oclint
           

安装 xcpretty

gem install xcpretty
           

在xcode里查看结果

1.创建Aggregate类型的Target

2.Build Phases 选项卡中选择 Add Run Script

3.拷贝脚本

source ~/.bash_profile
cd ${PROJECT_DIR}
xcodebuild clean
xcodebuild| xcpretty -r json-compilation-database -o compile_commands.json
oclint-json-compilation-database -report-type xcode
//也可以在xcodebuild后添加参数
           

读懂扫描报告

OCLint Report Summary: TotalFiles= FilesWithViolations= P1= P2= P3= /Users/issuser/Desktop/OCLintTest/OCLintTest/ViewController.m::: dead code [basic|P2] /Users/issuser/Desktop/OCLintTest/OCLintTest/ViewController.m::: short variable name [naming|P3] Length of variable name `i` is , which is shorter than the threshold of  
...
/*
报告显示:共扫描了个文件,其中有问题的文件数个。
p1:级为个
p2: 级为个(从下面的代码可以看出为dead code),类似于在return语句后写的代码
p3: 级为个,该级别比较低。例如一行写的代码超过个字符就会被列为级。 
*/