-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preprocessor to support .html.erb
files (Ruby on Rails, ERB)
#223
Comments
.html.erb
files.html.erb
files (Ruby on Rails, ERB)
@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. |
Hey, I noticed that I didn't have too much work to do to support Keep in mind that it comes with the same caveats like the JS linting with my processor, i.e. <%= if @var %>
<div class="foo" data-foo="bar">
<p>Hello</p>
</div>
<% end %> will be autocorrected to <%= if @var %>
<div class="foo" data-foo="bar">
<p>Hello</p>
</div>
<% end %> But this is something I can live with and it motivates to outsource more logic to Rails helpers or to do more logic in Rails in general ;) |
@yeonjuan I recently stumbled on this case where my plugin currently fails to provide reasonable output. Assume this HTML code (referred to as [1]): <button id="nice"
<% if current_user.admin? %>
class="btn-admin"
<% end %>
</button> What my plugin gives to <button id="nice"
<!-- 566513c5d83ac26e15414f2754 0 -->
class="btn-admin"
<!-- 566513c5d83ac26e15414f2754 1 -->
</button> Linting this with the following setting: "@html-eslint/sort-attrs": "error", will produce invalid code. I cannot expect you to lint [2] properly, since it isn't even valid HTML: in an attribute list, no comments are allowed. Would it still be possible to tailor for this special case? Or do you have a better idea for what I could use as replacement string? |
Hi1 @Splines This is probably a similar issue to #231. |
Hi, @@Splines npm install -D @html-eslint/[email protected] @html-eslint/[email protected] import eslintHTML from "@html-eslint/eslint-plugin";
import eslintHTMLParser, { TEMPLATE_ENGINE_SYNTAX } from "@html-eslint/parser";
export default [
{
"files": ["**/*.html"],
"languageOptions": {
parser: eslintHTMLParser,
parserOptions: {
templateEngineSyntax: TEMPLATE_ENGINE_SYNTAX.ERB // Configuration for ERB
}
},
"plugins": {
"@html-eslint": eslintHTML,
},
"rules": {
"@html-eslint/sort-attrs": ["error"]
}
},
] |
@yeonjuan Wow, that was quick, thanks a lot, I will give it a try this week. |
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 customESLint 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):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.The text was updated successfully, but these errors were encountered: