2015年12月4日 星期五

Swiftlint - 維護coding style的好工具

https://github.com/realm/SwiftLint

在多人協作開發專案時,遵守團隊訂出的coding style是一個好習慣,可以讓其他協作者更容易看懂我們產出的程式碼。Realm釋出的這個tool就可以幫助我們將專案中不符合coding style的地方用warning甚至是error標出,利用Xcode幫我們自動把關,節省其他協作者幫我們檢查coding style的時間。目前Swiftlint是遵照GitHub’s Swift Style Guide 做檢查。

安裝

brew install swiftlint

設定

lint

在target的run script加入

if which swiftlint >/dev/null; then
  swiftlint
else
  echo "SwiftLint does not exist, download from https://github.com/realm/SwiftLint"
fi

然後在Xcode裡Build專案,哇,怎麼連Pod裡面的code都檢查了呢?

在專案root path新建一個 .swiftlint.yml 檔案,輸入

included:
  - YourProjectSourceDirectiryName

把YourProjectSourceDirectiryName替換成你的專案原始碼資料夾名稱就可以只檢查自己專案的coding style囉。

沒有留言:

張貼留言