yeonjuan / html-eslint

ESLint plugin for linting HTML
https://html-eslint.org
MIT License
162 stars 28 forks source link

Preprocessor to support `.html.erb` files (Ruby on Rails, ERB) #223

Open Splines opened 3 weeks ago

Splines commented 3 weeks ago

Hey there, thanks so much for creating this tool. I'm wondering how all the people programmed HTML all those years without a proper HTML linter? Like as if the W3C Validator is one of the top results when I search for "HTML linter" on the web 😂


I'd like to lint the HTML part of .html.erb files. ERB is a templating language used in Ruby on Rails projects. In order to lint .js.erb files, I've written a custom ESLint plugin, which is essentially a preprocessor (and then also a postprocessor) to strip away all the ERB parts in the code (replacing them with a dummy comment), while keeping track of the positions to correctly map line and colon numbers of ESLint messages. Here's what you can achieve with it (image should be animated):

293907467-623d6007-b4f5-41ce-be76-5bc0208ed636

I was wondering if your project also supports some kind of mechanism such that I could use this preprocessor again (maybe with only slight changes) for .html.erb files. The recommended ESLint configuration basically just declares the processor.

This would allow me to lint the HTML part of these files. I would then use a tool like ERB Lint to lint the ERB parts.

yeonjuan commented 3 weeks ago

@Splines hello. Thanks for the suggestion, I agree with adding a preprocessor. However, I am not very familiar with ERB, so if I were to implement it, it might take some time. I will refer to the code you shared. Thank you.