[Easy] How to automatically format Ruby erb file with vsCode

When I was studying Rails this time and wanted to be able to automatically format erb files as well, I was researching various things, and there was an extension called Beautyify that made it possible to automatically format erb files.

This time I will introduce the method. If you have any suggestions or "I should do this more", I would appreciate it if you could comment.

Install Beautify

Click the fifth icon from the top on the far left of the editor (below the icon with the triangle mark), enter Beautify in the search window, and click Beautify. The screen below will appear, so click install. (The image is already installed, so it is uninstalled) コメント 2020-06-10 141341.png

Write settings.json.

Press the command key (ctrl on Windows) and the key to open the Settings screen and search for Beautify: language. After that, if you click ** Edit in setting.json ** written in a little small letters, settings.json will open, so write as follows.

settings.json


...

"beautify.language": {
    "js": {
      "type": ["javascript", "json"],
      "filename": [".jshintrc", ".jsbeautifyrc"]
      // "ext": ["js", "json"]
      // ^^ to set extensions to be beautified using the javascript beautifier
    },
    "css": ["css", "scss"],
    "html": ["htm", "html", "erb"] //"erb"Add
    // ^^ providing just an array sets the VS Code file type
  }

Adding ** "erb" ** to the html item will now format it. By the way, I set js and css to be formatted as well, but if you don't need it, you don't have to write it.

Supplement

Those who are not automatically formatted when saved

Add the following code to ** settings.json ** and save it.

"editor.formatOnSave": true, //Automatic format when saving file

I think that it will be automatically formatted when saving.

Summary

I don't think code formatting is very essential, so I introduced it to save resources. Please introduce it if you like.

Recommended Posts

[Easy] How to automatically format Ruby erb file with vsCode
How to convert erb file to haml
How to compile Java with VsCode & Ant
How to achieve file download with Feign
[Easy] How to upgrade Ruby and bundler
How to achieve file upload with Feign
[Ruby] How to convert CSV file to Yaml (Yml)
If you use SQLite with VSCode, use the extension (how to see the binary file of sqlite3)
How to automatically generate ER diagram when migrating with Rails6
How to request a CSV file as JSON with jMeter
[Ruby] How to split each GraphQL query into a file
How to decompile apk file to java source code with MAC
How to use Ruby return
Format Ruby with VS Code
[Ruby] How to comment out
Learning Ruby with AtCoder 13 How to make a two-dimensional array
How to number (number) with html.erb
How to update with activerecord-import
Ruby: How to use cookies
[Ruby] How to write blocks
How to deal with different versions of rbenv and Ruby
How to change the file name with Xcode (Refactor Rename)
How to make a jar file with no dependencies in Maven
How to realize huge file upload with TERASOLUNA 5.x (= Spring MVC)
How to open a script file from Ubuntu with VS code
Learning Ruby with AtCoder 11 How to receive frequently used standard input
Automatic file upload with old Ruby gem What to do with Watir
How to realize huge file upload with Rest Template of Spring
How to get started with slim
Convert ruby object to JSON format
How to iterate infinitely in Ruby
How to install ruby through rbenv
How to enclose any character with "~"
How to use Ruby on Rails
How to install Bootstrap in Ruby
[Ruby] How to use any? Method
How to use mssql-tools with alpine
How to get along with Rails
[Beginner] How to delete NO FILE
How to use Ruby inject method
How to execute Ruby irb (interactive ruby)
How to start Camunda with Docker
[IntelliJ IDEA] How to automatically add final when saving a Java file
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
If you want to make a zip file with Ruby, it's rubyzip.
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
How to start a Docker container with a volume mounted in a batch file
How to bind request parameters in list format with bean property in Spring
How to insert processing with any number of elements in iterative processing in Ruby
[For super beginners (more screenshots)] Automatically deploy to AWS ECR / ECS with Ruby2.6 x Rails6 x CircleCi [Hands-on format]
[Xcode] How to add a README.md file
How to crop an image with libGDX
How to adjustTextPosition with iOS Keyboard Extension
[Ruby] Handle instance variables with instance methods
Handle DatePicker with Ruby / gtk3 + glade3
Read environment variables with ruby ​​file [Super beginner]
Install Ruby 3.0.0 with asdf
Handle files with NIO.2.
Handle devise with Rails
Handle JSON with minimal-json
Getting Started with Ruby
11th, Classification with Ruby
Evolve Eevee with Ruby
How to request a CSV file as JSON with jMeter
[Easy] How to automatically format Ruby erb file with vsCode
How to get date data in Ruby
[Java] How to use the File class
How to delete the wrong migration file
[Rails] How to convert from erb to haml
[Java] How to compare with equals method
How to blur an image (super easy)
[Android] How to deal with dark themes