OCLint 教程

OCLint 安裝方法

主要步驟

安裝GodEyes_iOS

參考 GodEyes官網 http://godeyes.duapp.com/readme.jsp ,下載后無需安裝

1. 配置 GodEyes

打開 conf/config.ini 配置文件,根據你的項目需求,進行如下設置:

1)?ProjectPath:要掃描的工程路徑,即擁有 xxx.xcodeproj 文件或 xxx.xcworkspace 的目錄

2)?xctoolCommand:這一步可能需要你費點心思。GodEyes 依賴一個叫做json編譯數據庫(json Compilation Database)的文件來獲取需要掃描的文件列表,而這個文件可以通過調用 GodEyes 內置的第三方工具 xctool 來生成。然而,xctool 并不是很聰明,你需要告訴 xctool 一些關于你項目的必要信息,才能讓 xctool 正確生成編譯數據庫。以下是一個示例:

xctoolCommand = xctool/bin/xctool -project /HelloWorld.xcodeproj -scheme HelloWorld -sdk iphonesimulator -reporter json-compilation-database:/compile_commands.json clean build

2完成配置后,cd 進入 godeyes 目錄,然后直接 sh main.sh 執行腳本即可。

主要生成compile_commands.json,后面oclint要使用這個文件

2.GodEyes掃描規則

http://godeyes.duapp.com/scanrule.jsp

二。安裝oclint

下載oclint并安裝

下載地址:?http://oclint.org/downloads.html

選擇mac os x或者darwin的包,下載到本地。

打開~/.bash_profile,如果沒有新建一個,輸入

OCLINT_HOME=/path/to/oclint目錄

export PATH=$OCLINT_HOME/bin:$PATH

http://www.tuicool.com/articles/AnEnMzf

三。安裝xcpretty

https://github.com/supermarin/xcpretty

gem install xcpretty

四,集成到xcode

參考文檔http://docs.oclint.org/en/stable/guide/xcode.html

在 bin/sh 下面輸入

生成html報告

source ~/.bash_profile

cd ${SRCROOT}

xcodebuild clean

xcodebuild | xcpretty -r json-compilation-database

oclint-json-compilation-database oclint_args "-disable-rule=UnusedMethodParameter -disable-rule=LongLine -disable-rule=LongMethod -disable-rule=NcssMethodCount -disable-rule=ObjCObjectSubscripting -disable-rule=LongClass? -disable-rule=NcssMethodCount -disable-rule=NPathComplexity -disable-rule=NPathComplexity -rc LONG_VARIABLE_NAME=1200 " -- -report-type html? -o oclintReport.html

如果是在xcode里面看,改寫type

source ~/.bash_profile

cd ${SRCROOT}

xcodebuild clean

xcodebuild | xcpretty -r json-compilation-database

oclint-json-compilation-database oclint_args "-disable-rule=UnusedMethodParameter -disable-rule=LongLine -disable-rule=LongMethod -disable-rule=NcssMethodCount -disable-rule=ObjCObjectSubscripting -disable-rule=LongClass? -disable-rule=NcssMethodCount -disable-rule=NPathComplexity -disable-rule=NPathComplexity -rc LONG_VARIABLE_NAME=1200 " -- -report-type xcode

oclint_args "-disable-rule=UnusedMethodParameter -disable-rule=LongLine -disable-rule=LongMethod -disable-rule=NcssMethodCount -disable-rule=ObjCObjectSubscripting -disable-rule=LongClass? -disable-rule=NcssMethodCount -disable-rule=NPathComplexity -disable-rule=NPathComplexity -rc LONG_VARIABLE_NAME=1200 “

oclint_args指的是oclint 的檢測規則,-disable-rule 屏蔽某條規則

-rc LONG_VARIABLE_NAME=1200 制定某條規則的參數

參考文檔

http://oclint-docs.readthedocs.io/en/stable/rules/migration.html

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容