Reputation: 145
I dont like posting what should be a simple question, but I have spend days looking for the answer and I have uninstalled and re-installed vscode but I still have the issue. Any loop structure within a html.erb file gets un-indented.
<%if true%>
<p>Something</p>
<%end%>
will get formatted back to
<%if true%>
<p>Something</p>
<%end%>
I have ruby-rubocop installed for the formatter and here is my settings.json
"workbench.iconTheme": "vscode-icons-mac",
"editor.formatOnSave": true,
"ruby.format": "rubocop",
"editor.tabSize": 2,
"editor.detectIndentation": false,
"files.associations": {
"html.erb": "erb"
},
Any thoughts on what I am missing? Certainly there is a setting that I am missing, and that this wouldn't be a feature that is unsupported.
Upvotes: 4
Views: 2856
Reputation: 1482
TL;DR: Replace html
with *
on your config and it should work.
I had the same problem as you and I gladly found a fix. At least, it worked for me.
Initially, I thought what did the trick was installing an extension called ERB Formatter/Beautify.
Then, I realized, just by following their install instructions, that the ERB was probably being recognized as an HTML file and not ERB. And the formatting was probably working fine. It was just not understanding it was ruby code, but rather HTML.
The extension recommends you adding the below code to settings.json
, because sometimes we people tell them the extension does not work if the file is *.html.erb
instead of *.erb
. And that tends to be rails defaults.
"files.associations": {
"*.erb": "erb"
}
So, all you need to do is replace html
with *
on your config and it should work.
If that doesn't work, please try installing this extension.
Upvotes: 5