1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[VSCode]Rails x Docker環境でRubocopuの自動フォーマット

Posted at

はじめに

備忘録として残します
フロントエンドのPrettierみたいに、Rails環境でもformat on saveする方法を探していました。
ホストにrubocopを用意して...とかDev Containerを使って...とかやりたくなかったので、超シンプルに実現できて満足

前提

Railsの動くDocker環境

Docker環境の用意がない場合はこちらご利用ください

sqlite

mysql

rubocopt

group :development do
  gem 'rubocop', require: false
end
$ bundle install

VSCodeの拡張機能をinstall

rubocop用の設定ファイルを作成

$ touch ./bin/rubocop
$ chmod 744 ./bin/rubocop
#!/bin/bash
cd $(dirname $0)/..
OPTION=$(test -p /dev/stdin && echo '-T')
docker compose exec $OPTION app rubocop --server $@

setting.json

"ruby.rubocop.executePath": "./bin/",
  "[ruby]": {
    "editor.defaultFormatter": "misogi.ruby-rubocop"
  },

参考

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?