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.
Rubocop. Runs RuboCop on all ruby statements found in ERB templates.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With