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.
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)
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.
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.
I don't think code formatting is very essential, so I introduced it to save resources. Please introduce it if you like.
Recommended Posts