意識が高まり、OCLintを使ってみました。

手順

OCLintの公式のドキュメントを頑張って読んでも使い方はわかるのですが、
以下のリンク”Give a try”という項目に従うと手っ取り早く試せます。

Integrating OCLint in Xcode

結果

ISRefreshControlで試しました。 ご覧の通り、たくさん怒られています。

Pods/ISMethodSwizzling/ISMethodSwizzling/ISMethodSwizzling.m:9:1: long line P3 Line with 138 characters exceeds limit of 100
Pods/ISMethodSwizzling/ISMethodSwizzling/ISMethodSwizzling.m:10:1: long line P3 Line with 138 characters exceeds limit of 100
Pods/ISMethodSwizzling/ISMethodSwizzling/ISMethodSwizzling.m:23:1: long line P3 Line with 138 characters exceeds limit of 100
Pods/ISMethodSwizzling/ISMethodSwizzling/ISMethodSwizzling.m:24:1: long line P3 Line with 138 characters exceeds limit of 100
Pods/ISMethodSwizzling/ISMethodSwizzling/ISMethodSwizzling.m:18:5: parameter reassignment P3
ISRefreshControl/ISGumView.m:59:1: long line P3 Line with 124 characters exceeds limit of 100
ISRefreshControl/ISGumView.m:132:1: long line P3 Line with 105 characters exceeds limit of 100
ISRefreshControl/ISGumView.m:133:1: long line P3 Line with 102 characters exceeds limit of 100
ISRefreshControl/ISGumView.m:141:1: long line P3 Line with 111 characters exceeds limit of 100
ISRefreshControl/ISGumView.m:162:1: long line P3 Line with 103 characters exceeds limit of 100
ISRefreshControl/ISGumView.m:167:1: long line P3 Line with 103 characters exceeds limit of 100
ISRefreshControl/ISGumView.m:189:1: long line P3 Line with 101 characters exceeds limit of 100
ISRefreshControl/ISGumView.m:197:1: long line P3 Line with 101 characters exceeds limit of 100
ISRefreshControl/ISGumView.m:205:1: long line P3 Line with 105 characters exceeds limit of 100
ISRefreshControl/ISGumView.m:146:1: long method P3 Method with 64 lines exceeds limit of 50
ISRefreshControl/ISGumView.m:146:1: high ncss method P2 Method of 50 non-commenting source statements exceeds limit of 30
ISRefreshControl/ISRefreshControl.m:154:5: collapsible if statements P3
ISRefreshControl/ISRefreshControl.m:166:1: high cyclomatic complexity P2 Cyclomatic Complexity Number 16 exceeds limit of 10
ISRefreshControl/ISRefreshControl.m:34:13: inverted logic P3
ISRefreshControl/ISRefreshControl.m:35:1: long line P3 Line with 108 characters exceeds limit of 100
ISRefreshControl/ISRefreshControl.m:143:1: long line P3 Line with 102 characters exceeds limit of 100
ISRefreshControl/ISRefreshControl.m:152:1: long line P3 Line with 124 characters exceeds limit of 100
ISRefreshControl/ISRefreshControl.m:175:1: long line P3 Line with 106 characters exceeds limit of 100
ISRefreshControl/ISRefreshControl.m:179:1: long line P3 Line with 104 characters exceeds limit of 100
ISRefreshControl/ISRefreshControl.m:275:1: long line P3 Line with 115 characters exceeds limit of 100
ISRefreshControl/ISRefreshControl.m:187:5: missing break in switch statement P3
ISRefreshControl/ISRefreshControl.m:187:5: switch statements should have default P3
ISRefreshControl/UITableViewController+ISRefreshControl.m:14:1: long line P3 Line with 109 characters exceeds limit of 100
ISRefreshControl/UITableViewController+ISRefreshControl.m:15:1: long line P3 Line with 113 characters exceeds limit of 100
ISRefreshControl/UITableViewController+ISRefreshControl.m:16:1: long line P3 Line with 106 characters exceeds limit of 100
ISRefreshControl/UITableViewController+ISRefreshControl.m:45:1: long line P3 Line with 109 characters exceeds limit of 100
ISRefreshControl/UITableViewController+ISRefreshControl.m:50:1: long line P3 Line with 108 characters exceeds limit of 100
ISRefreshControl/UITableView+ISRefreshControl.m:12:1: long line P3 Line with 105 characters exceeds limit of 100
ISRefreshControl/ISScalingActivityIndicatorView.m:51:1: long line P3 Line with 107 characters exceeds limit of 100
ISRefreshControl/ISScalingActivityIndicatorView.m:56:1: long line P3 Line with 107 characters exceeds limit of 100
ISRefreshControl/ISScalingActivityIndicatorView.m:61:1: long line P3 Line with 104 characters exceeds limit of 100
ISRefreshControl/ISScalingActivityIndicatorView.m:65:1: long line P3 Line with 110 characters exceeds limit of 100
ISRefreshControl/ISScalingActivityIndicatorView.m:78:1: long line P3 Line with 101 characters exceeds limit of 100
ISRefreshControl/ISScalingActivityIndicatorView.m:87:1: long line P3 Line with 101 characters exceeds limit of 100
ISRefreshControl/ISScalingActivityIndicatorView.m:95:1: long line P3 Line with 104 characters exceeds limit of 100
ISRefreshControl/ISScalingActivityIndicatorView.m:99:1: long line P3 Line with 110 characters exceeds limit of 100

レポートの出力時に-o=report.html -htmlをつけるとHTMLのレポートも出してくれます。

感想

OCLintの警告にはそれぞれの1〜3のPriorityがつけられていて、値が小さいほどやばいものです。
今回の結果ではP2, P3の警告が出ていたので、それらについて感想を書きます。

P3

  • long line (行が100文字以上)
  • long method (メソッドが50行以上)
  • parameter reassignment (変数が使い回されている)
  • collapsible if statements (分解できる(?)if文がある)
  • switch statements should have default (defaultがないswitch文がある)

全体的に正しいのですが、改めて指摘されると舌打ちしたくなるというのがP3の感想です。

defaultがないswitch文は、typedefしてXcodeにcase漏れをチェックさせるようにしていたので、
そちらの方を優先しようかなあと思いました。(defaultを書くとcase漏れを見つけにくいので。)

P2

  • high ncss method (30行以上コメントがないメソッドがある)
  • high cyclomatic complexity (cyclomatic complexityが10以上(とにかくなんか複雑らしい))

P3と比べると謝る気が起きる内容でした。

この記事を書いている間に意識が下がってしまったので、OCLintは一旦見送ることにしました。
これから使い始める人はP1, P2あたりから気にすると良いのではないでしょうか。