toshizou-Rails

VSCodeでRuboCopによる警告文一覧(随時追加)

共通(?)

Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.

Align the keys of a hash literal if they span more than one line.

Please use Rails.root.join('path/to') instead.

  • Rails/FilePathで制御
  • 相対パスで書き直してねという警告
  • 私はオフにしています
# bad
Dir[Rails.root.join('spec', 'support', '**', '*.rb')]
# good
Dir[Rails.root.join('spec/support/**/*.rb')]




Align the arguments of a method call if they span more than one line.

  • Layout/ArgumentAlignmentで制御
  • メソッド呼び出しの引数が複数行にわたる場合は、それらを揃えてねという内容
  • 私の場合はgem seed_fuを使用するときに表示されました
# bad
Unit.seed_once(:id,
  { id: 1, name: "なし" },
)

# good
Unit.seed_once(
  :id,
  { id: 1, name: "なし" },
)




DB関連

You can use change_table :xxxs, bulk: true to combine alter queries

remove_column(without type) is not reversible.

Method definitions must not be nested. Use lambda instead.

Uniqueness validation should be with a unique index.

  • Rails/UniqueValidationWithoutIndexで制御
  • modelファイルのvalidation編集時に表示
  • modelの記述とDBの定義が矛盾しているときに表示する

    RDBMSのunique indexがついていないカラムに対して、Active Recordのレイヤーでuniquenessバリデーションを書いている場合に警告をします。 - Rails/UniqueValidationWithoutIndex copを追加した - pockestrap


Specify an :inverse_of option.

Specify a :dependent option.

RSpec

Start context description with 'when', 'with', or 'without'.

  • RSpec/ContextWordingで制御
  • contextを使うときは'when','with', 'without'のどれかを説明の最初につけてねという警告


Example has too many lines [x/y].

  • RSpec/ExampleLengthで制御
  • Example(it)1つに色々つめこみすぎ、やること絞ってねという警告
  • 場合によっては詰め込みたい場合もあるからspecの種類ごとに除外しても良いかも


Example has too many expectations [x/y]

  • RSpec/MultipleExpectationsで制御
  • expect構文を使いすぎるな(it 1つにつき expect 1つだよ)という警告




参考サイト