Rubocop: Support parsing erb files

Created on 26 May 2014  路  8Comments  路  Source: rubocop-hq/rubocop

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.

Most helpful comment

We're looking at writing this.

@bbatsov is this still out of scope of rubocop or would you accept a patch making rubocop depend on an .erb parser like https://rubygems.org/gems/erubis/versions/2.7.0.

All 8 comments

That's beyond the scope of the core RuboCop project. Someone has to create a project similar to haml-lint, which uses RuboCop internally.

I have to say that I was surprised that my view files were untouched after running this in my rails project. I wanted all my code converted, whether embedded in an html.erb, or just plain ruby in an .rb file. I was trying to update all of my old ruby hash syntax to the new syntax easily/automatically.

I don't even think it would be that hard to have it parse anything inside a <%= %>. I guess your response would be "then write it yourself!" Was there any other showstoppers that were keeping this out of the scope? Or are you guys just not Rails people, or just prefer to keep this project framework agnostic, which means skip .html.erb? (WAT IS YOUR REASONING?!...haha)

Is there anything else out there that could parse my .html.erb files and convert them to the new ruby hash syntax?

@gregblass i have a perl script for this if you are still looking.

@askl56 please share :)

There is a gem called Ruumba which does that.

However, it just uses a regex to extract everything between <%=, <% and %>, copies the extracted code into temporary files, executes rubocop and then deletes those files again. This is suboptimal for error messages, automatic corrections and configurations, so I guess something better would be nice still.

We're looking at writing this.

@bbatsov is this still out of scope of rubocop or would you accept a patch making rubocop depend on an .erb parser like https://rubygems.org/gems/erubis/versions/2.7.0.

Jeez I was a little aggressive two years ago, wasn't I? Apologies for that.

I just returned back here since prettier is all the rage these days and really wished I could have that type of thing work with Rails.

Cool to see that it's under consideration! As I work on code that I haven't touched more and more, I find that .erb files are probably my biggest sources of sloppiness, or at least just different code styles from how I write now.

Ruumba actually looks like it should do the trick for me though! I don't think I would even mind the inefficiencies.

For those still looking there's ERB Lint which integrates with Better HTML. 馃寪

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deivid-rodriguez picture deivid-rodriguez  路  3Comments

Aqualon picture Aqualon  路  3Comments

benoittgt picture benoittgt  路  3Comments

mikegee picture mikegee  路  3Comments

kirrmann picture kirrmann  路  3Comments