RubyのLinterといえばrubocop
だと思うのですが、個人のツールとかだと最近standardrb
を使うことが多いので使い感とかをメモしておきます📝
standardrbとは?
StandardJSインスパイのRubyのLinterです。
This gem is a spiritual port of StandardJS and aims to save you (and others!) time in the same three ways:
- No configuration. The easiest way to enforce consistent style in your project. Just drop it in.
- Automatically format code. Just run standardrb --fix and say goodbye to messy or inconsistent code.
- Catch style issues & programmer errors early. Save precious code review time by eliminating back-and-forth between reviewer & contributor.
記載の通り、rubocopのように.rubocop.yml
に毎回無効にするルールと記載するといった対応が不要で手軽に使えるのと、自動修正といった機能も備えています。
standardrbの使い方
基本的にはstandardrb
をGemfileに追加し、bundle installを実行するだけで準備OKです。
あとは以下を実行することで静的解析を行う事ができます。
$ bundle exec standardrb
また設定不要で使えますが、特定のファイルは静的解析の対象外としたい場合には.standard.yml
を用意してあげます。
ignore: - 'some/file/in/particular.rb' - 'a/whole/directory/**/*'
おわりに
rubocop
だと、以下のような日本語だと絶対に引っかかる特定のルールをまずは無効化するみたいなことをするのですが、そういうのがいらないのと、スタイル周りとか厳しすぎずストレスの感じにくい、いい感じのルールが自動で設定してくれるのがいいなぁと思っています。
standardrbはrubocopをもとに作られているのみたいですね、rubocopをベースにしているルールは以下で確認できそうです。