0
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にrubocopの追加

Last updated at Posted at 2025-10-21

gemfileの作成

$bundle init

gemfileに以下の記述を追加

group :development do
  gem "ruby-lsp", "~> 0.26.1"
  gem "rubocop", require: false
end

$bundle installの実行

設定ファイルを開き、記述の追加

コマンドパレット(⌘⇧P)から「Preferences: Open Settings (JSON)」を開き
以下の記述を追加

{
    "editor.formatOnSave": true,
    "editor.tabSize": 2,
    "editor.insertSpaces": true,
    "rubyLsp.formattingProvider": "rubocop",
    "rubyLsp.diagnostics": true
}

rubocop.ymlの設定

1.rubocop.ymlというファイルを作成

以下の設定内容を参考に中身を記述
https://github.com/rails/rails/blob/main/.rubocop.yml

2.gemfileに以下の記述を追加

group :development do
  gem 'rubocop-md', require: false
  gem 'rubocop-minitest', require: false
  gem 'rubocop-packaging', require: false
  gem 'rubocop-performance', require: false
  gem 'rubocop-rails', require: false
end

$bundle installの実行

設定できたかの確認

  1. VSCode を再起動
  2. 再起動後、右下の {} マークにカーソルを合わせると以下のように表示されました
Spell
Completions
Disabled
Addons: 1
18/18 features enabled
Formatter: rubocop
Using Ruby 3.2.9 with rbenv
Ruby LSP server v0.26.1: Running

formatterの部分がrubocopにならない場合は

  1. vscodeの設定(comannd,)を開き、検索欄にRuby LSP と入力
  2. Ruby Lsp: Formatterの項目をrubocopに変更

rubocopの実行

$bundle exec rubocopを実行
Inspecting n filesのように出れば成功です
修正箇所を自動的に修正したい時は$bundle exec rubocop -aを実行

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