rubocopを使ってみる

rubocopを使ってみる

とりあえず $ bundle exec rubocop lib/ をやってみると、「11 files inspected, 252 offenses detected」

目につくのはこれだな。

lib/entry_reformat.rb:12:9: C: Use 2 (not 4) spaces for indentation.
parser = Oga.parse_html(html_text)
^^^^

tabがspace4になっているからですね。これは直したくないので設定の方を変える。

projectの下に.rubocop.ymlを作って

Style/IndentationWidth:
Width: 4

で「11 files inspected, 167 offenses detected」になる(ということは90行しか書いてないのか?)

まぁ次

Style/IndentationWidth: lib/my_rss.rb:6:61: C: Prefer single-quoted strings when you don't need string interpolation or special symbols.
def initialize(title, html_url, xml_url, category = "uncategorized")
^^^^^^^^^^^^^^^

ダブルクォーテーションだけ使う所存

Style/StringLiterals:
EnforcedStyle: double_quotes

「11 files inspected, 90 offenses detected」(70箇所以上もあったか?って感じだが...)

あとは「andじゃなくて&&」「notじゃなくて!」とか...

Style/AndOr:
Enabled: false
Style/Not:
Enabled: false

更に「Hash.newじゃなく{}」「Array.newじゃなく[]」賛成。「11 files inspected, 55 offenses detected」

「Missing top-level class documentation comment.」あわわわ...これはちょっとつらいな。

面白いのは「Trailing whitespace detected.」とか。末尾スペース削除して回れってかよ無理です。