天天看點

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: 級為個,該級别比較低。例如一行寫的代碼超過個字元就會被列為級。 
*/