Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rubocop in html.erb files?

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.

like image 733
Mike Avatar asked Nov 16 '13 23:11

Mike


People also ask

Does RuboCop format ERB?

Rubocop. Runs RuboCop on all ruby statements found in ERB templates.

What is HTML ERB file?

As @Chowlett mentioned before, erb stands for Embedded Ruby. When you define any file as ". html. erb" that means it's an HTML file with ruby code embedded in it and it is similar to ". rhtml" extension of rails file.

How do I view HTML ERB?

View templates HTML tags provide static web pages only but ERB tags give us dynamic information in that HTML template. To view the template file, go to Rails application >> app >> View>> Home folder where the templates files are available.

How do ERB files work?

An ERB object works by building a chunk of Ruby code that will output the completed template when run. If safe_level is set to a non-nil value, ERB code will be run in a separate thread with $SAFE set to the provided level. eoutvar can be used to set the name of the variable ERB will build up its output in.


1 Answers

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.

like image 178
Andrew Grimm Avatar answered Sep 25 '22 08:09

Andrew Grimm