下記関数を.bashrcなりに追加して、virc <ソースDIR>
すれば(出力フォーマットをカスタマイズしていなければ)コードのpathと行番号が出力されている部分を選択すると、その行をvimで開くことが出来る
# rubocopの結果をvimで開くfunction virc {DIR="$1"F=$(rubocop ${DIR}| peco | awk -F ":"'{print "-c "$2" "$1}')if[$? -eq 0 -a "${F}" !=""]theneval"vi ${F}"fi}
lhmのソースでの実行例
QUERY> IgnoreCase [239(1/5)]
Inspecting 17 files
.CW.CC.CCC.CCC...
Offenses:
lib/lhm/atomic_switcher.rb:38:27: C: Space inside string interpolation detected. # この行を選択"rename table `#{ @origin.name }` to `#{ @migration.archive_name }`, "\
^^^^^^^^^^^^
lib/lhm/atomic_switcher.rb:38:50: C: Space inside string interpolation detected.
"rename table `#{ @origin.name }` to `#{ @migration.archive_name }`, "\
^^^^^^^^^^^^^^^^^^^^^^^
lib/lhm/atomic_switcher.rb:39:14: C: Space inside string interpolation detected.
"`#{ @destination.name }` to `#{ @origin.name }`"
^^^^^^^^^^^^^^^^^
lib/lhm/atomic_switcher.rb:39:42: C: Space inside string interpolation detected.
"`#{ @destination.name }` to `#{ @origin.name }`"
^^^^^^^^^^^^
lib/lhm/atomic_switcher.rb:46:20: C: Space inside string interpolation detected.
error "`#{ @origin.name }` and `#{ @destination.name }` must exist"
^^^^^^^^^^^^
lib/lhm/atomic_switcher.rb:46:44: C: Space inside string interpolation detected.
error "`#{ @origin.name }` and `#{ @destination.name }` must exist"
^^^^^^^^^^^^^^^^^
lib/lhm/atomic_switcher.rb:53:7: C: Redundant begin block detected.
begin
^^^^^
:
:
atomic_switcher.rb
22definitialize(migration,connection=nil)23@migration=migration24@connection=connection25@origin=migration.origin26@destination=migration.destination27@retries=028@max_retries=MAX_RETRIES29@retry_sleep_time=RETRY_SLEEP_TIME30end3132defstatements33atomic_switch34end3536defatomic_switch37[38"rename table `#{@origin.name}` to `#{#@migration.archive_name }`, " \ # この行が選択された状態で開く39"`#{@destination.name}` to `#{@origin.name}`"40]41end4243defvalidate44unless@connection.table_exists?(@origin.name)&&45@connection.table_exists?(@destination.name)46error"`#{@origin.name}` and `#{@destination.name}` must exist"47end48end