1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ERBFormatter/Beautify 設定

Posted at

はじめに

html.erbファイルを保存するときに自動でフォーマットされるようにします。
フォーマッターにはERBFormatter/Beautifyを使います。
https://github.com/aliariff/vscode-erb-beautify

環境

rails 6.1.7
ruby 3.0.6

extensions.json

フォーマッターの設定は.vscode直下にsettings.jsonextensions.jsonを作成して行います。
今回使うExtensionをjsonに設定しましょう。

.vscode/extensions.json
{
  "recommendations": [
    "aliariff.vscode-erb-beautify"
  ]
}

htmlbeautifier

ERBFormatter/Beautifyは内部的にhtmlbeautifierを使っているのでPCにインストールします。

gem install htmlbeautifier

あとで設定する時にhtmlbeautifierの実行パスが必要になるので調べておきます。

rbenv which htmlbeautifier

settings.json

後はsettings.jsonに設定を記載します。

.vscode/settings.json
{
  "files.associations": {
    "*.html.erb": "erb"
  },
  "[erb]": {
    "editor.defaultFormatter": "aliariff.vscode-erb-beautify",
    "editor.formatOnSave": true
  },
  "vscode-erb-beautify.executePath": "path_to_htmlbeautifier",
  "vscode-erb-beautify.customEnvVar": {
    "LC_ALL": "en_US.UTF-8"
  }
}

参考リンク

https://qiita.com/pokeneko/items/c80be1af2edb7698f248
https://www.y-i.jp/entry/auto-format-erb-vscode

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?