I was curious if there was a way to make Rubocop lint/stylecop html.erb files? I realize that the html would make it hard to style cop the embedded Ruby. Has anyone been able to get Rubocop to do this? If not, is there an equivalent tool for this purpose? I have used rails_best_practices and it doesn't quite work as desired.
Asked
Active
Viewed 1.0k times
1 Answers
22
There is a linting gem called ERB lint which includes RuboCop.
Previous version of answer
In May 2014, there was a feature request asking for this functionality in RuboCop, and it was rejected by the head of the project.
Request:
Right now when I try to run rubocop on an erb template it does not parse out the ruby code. It would be nice to run rubocop on every file that has ruby code in it.
Reply:
That's beyond the scope of the core RuboCop project. Someone has to create a project similar to haml-lint, which uses RuboCop internally.

Andrew Grimm
- 78,473
- 57
- 200
- 338
-
1I think it's cracy that rubocop runs on HAML but not on ERB, since ERB is the default for Rails. Do you have any updates? Did nobody create a erb-lint thing already? – amoebe Oct 19 '16 at 16:49
-
1Another gem that lints ERB files with Rubocop is Ruumba: https://github.com/ericqweinstein/ruumba I do not know how does it differs with ERB Lint. – ybart Apr 23 '19 at 14:47
-
1Any idea how to configure ERB Lint with VScode? – svelandiag Apr 07 '21 at 17:14
-
@amoebe it makes sense, HAML is much closer to Ruby than html.erb is. @svelandiag install extension `ERB Formatter/Beautify` and then `gem install htmlbeautifier` and it'll work. – januszm Oct 20 '22 at 17:04