DEV Community

Yuta Goto
Yuta Goto

Posted on

3 1

rubocop-yayoiを作った

rubocopの注意テキストが日本語だったらなーなんか好きなキャラクターから指摘されるとさらにいいかなーなんて思ったので作りました。

出来上がったもの

https://rubygems.org/gems/rubocop-yayoi

Rubocop::Yayoi

Build Status

ζ*'ヮ')ζ<うっうー!

このgemは rubocop 実行後に表示されるテキストがアイドルマスター 765プロ所属の高槻やよい風に指摘してくれるgemです!

Installation

Add this line to your application's Gemfile:

gem 'rubocop-yayoi'
Enter fullscreen mode Exit fullscreen mode

And then execute:

$ bundle

Or install it yourself as:

$ gem install rubocop-yayoi

Usage

RuboCop configuration file

Put this into your .rubocop.yml.

require: rubocop-yayoi

Now you can run rubocop and it will automatically load the RuboCop RSpec cops together with the standard cops.

Command line

rubocop --require rubocop-yayoi
Enter fullscreen mode Exit fullscreen mode

Rake task

RuboCop::RakeTask.new do |task|
  task.requires << 'rubocop-yayoi'
end
Enter fullscreen mode Exit fullscreen mode

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release

使い方

設定するだけです。

# .rubocop.yml
require:
  - rubocop-yayoi
Enter fullscreen mode Exit fullscreen mode

この状態で以下のrubyファイルを試しに用意します。

# index.rb
class Takatsuki_Yayoi
  def is_yayoi?(y, takatsuki)
    y && true
  end
end
Enter fullscreen mode Exit fullscreen mode

実行します。

$ bundle exec rubocop index.rb
[Warn] Performance Cops will be removed from RuboCop 0.68. Use rubocop-performance gem instead.
       https://github.com/rubocop-hq/rubocop/tree/master/manual/migrate_performance_cops.md

/Users/yutagoto/Documents/rubocop-yayoi/lib/rubocop/cop/layout/def_end_alignment.rb:8: warning: already initialized constant RuboCop::Cop::Layout::DefEndAlignment::MSG
/Users/yutagoto/Documents/yayoitest/vendor/bundle/ruby/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/layout/def_end_alignment.rb:40: warning: previous definition of MSG was here
# 定数を上書きしているワーニングがめっちゃ出るので省略

ζ*'ヮ')ζ<1ファイルチェックしますよー!
W

ζ*'ヮ')ζ<うっうー!!

index.rb:1:1: C: Style/Documentation: ζ*'ヮ')ζ<うっうー!classのドキュメントのコメントを書きましょうねー
class Takatsuki_Yayoi
^^^^^
index.rb:1:7: C: Naming/ClassAndModuleCamelCase: ζ*'ヮ')ζ<うっうー!モデル名やモジュール名にはCamelCaseを使いましょうねー!
class Takatsuki_Yayoi
      ^^^^^^^^^^^^^^^
index.rb:2:7: C: Naming/PredicateName: ζ*'ヮ')ζ<うっうー! is_yayoi? から yayoi? に名前を変えようねー!
  def is_yayoi?(y, takatsuki)
      ^^^^^^^^^
index.rb:2:17: C: Naming/UncommunicativeMethodParamName: ζ*'ヮ')ζ<うっうー!メソッドのパラメータの長さは最低でも3文字以上にしましょうねー!
  def is_yayoi?(y, takatsuki)
                ^
index.rb:2:20: W: Lint/UnusedMethodArgument: ζ*'ヮ')ζ<うっうー!使っていない引数がありますよー takatsuki! もし使わないなら、_か_takatsukiのようにしましょうねー!
  def is_yayoi?(y, takatsuki)
                   ^^^^^^^^^

ζ*'ヮ')ζ<うっうー!1ファイルチェックしましたよー!
ζ*'ヮ')ζ<うっうー!5こ怪しいですよー!
Enter fullscreen mode Exit fullscreen mode

こんな感じであたかも高槻やよいちゃんから指摘を受けているかのようにできます。うれしいですね。

いまはまだ一部の指摘にしか対応できていないので、今後増やしていく予定です。実質翻訳作業みたいなものなので、rubocopへの理解がかなり深まりそうな気がしています。(TODO:)

また、実行するたびに定数を上書きしているwarningがたくさん表示されてしまうので、もうちょっといい感じにmethodに切り出したり表示するロジックを改造したりしないといけない気がしています。(TODO:)

気が向いたら使ってやってください。

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs