LoginSignup
5
5

More than 5 years have passed since last update.

RuboCop | 任意の警告に対応するRuboCopのソースコードを爆速で表示する方法

Posted at

RuboCop | 任意の警告に対応するRuboCopのソースコードを爆速で表示する方法

概要

任意の警告に対応するRuboCopのソースコードを爆速で表示する方法について。

RuboCopの警告ですが、一つ一つの警告に対して細かなサンプルつきドキュメントなどがないため
警告がどのようなものか調べたい場合があります。
その場合、対象警告のソースコードとテストコードを確認するのが手っ取り早いです。
そこで、警告に対応するコードを素早く表示する方法を紹介します。

対象コード

hoge = nil

手順

  • 現在の警告を知るために、 todo ファイルを出力します
$ rubocop --auto-gen-config
$ cat rubocop-todo.yml
# This configuration was generated by `rubocop --auto-gen-config`
# on 2014-07-25 22:30:24 +0900 using RuboCop version 0.21.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
UselessAssignment:
  Enabled: false
  • 警告名 UselessAssignment をクリップボードにコピーします
  • ブラウザを起動して、Googleを表示します。
  • rubocop github 」 で検索を実行します

find_rubocop0.png

  • 検索結果の先頭に rubocop のGitHubリポジトリが表示されます

find_rubocop1.png

  • TAB => Enter でRuboCopのGitHubトップページに移動します

find_rubocop2.png

find_rubocop3.png

  • T キーを押下し、検索モードにします

find_rubocop4.png

  • クリップボードに保存しておいた、 UselessAssignment を貼り付けると対象のプロダクトコードとテストコードがフィルタされます

find_rubocop5.png

  • 矢印の下キー=>Ctrl + Enterでそれぞれを新たなタブに表示します

  • あとは好きなだけ中身を確認してください

補足

この方法は別途下記記事でも紹介している内容をRuboCop向けにしたものです。

GitHub | ショートカットを駆使して爆速で目的のソースコードを表示する

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5