Skip to content

Linter Rule: Disallow parser errors in HTML+ERB documents

Rule: parser-no-errors

Description

Report parser errors as linting offenses. This rule surfaces syntax errors, malformed HTML, and other parsing issues that prevent the document from being correctly parsed.

Rationale

Parser errors indicate fundamental structural problems in HTML+ERB documents that can lead to unexpected rendering behavior, accessibility issues, and maintenance difficulties. These errors should be fixed before addressing other linting concerns as they represent invalid markup that browsers may interpret inconsistently.

By surfacing parser errors through the linter, developers can catch these critical issues when running lint checks directly, without needing to switch to the language server or other tools.

Examples

✅ Good

html
<h2>Welcome to our site</h2>
<p>This is a paragraph with proper structure.</p>

<div class="container">
  <img src="image.jpg" alt="Description">
</div>
erb
<h2><%= @page.title %></h2>
<p><%= @page.description %></p>

<% if user_signed_in? %>
  <div class="user-section">
    <%= current_user.name %>
  </div>
<% end %>

🚫 Bad

html
<h2>Welcome to our site</h3>
Found closing tag `</h3>` at (1:25) without a matching opening tag in the same scope. (`MISSING_OPENING_TAG_ERROR`) (parser-no-errors)
Opening tag `<h2>` at (1:1) doesn't have a matching closing tag `</h2>` in the same scope. (`MISSING_CLOSING_TAG_ERROR`) (parser-no-errors)
html
<div>
  <p>This paragraph is never closed
Element `<p>` at (2:3) has its closing tag omitted. While valid HTML, consider adding an explicit `</p>` closing tag at (3:0) for clarity, or set `strict: false` to allow this. (`OMITTED_CLOSING_TAG_ERROR`) (parser-no-errors)
</div>
html
Some content
</div>
Found closing tag `</div>` at (2:2) without a matching opening tag in the same scope. (`MISSING_OPENING_TAG_ERROR`) (parser-no-errors)
erb
<!-- Invalid Ruby syntax in ERB -->
<%= 1 + %>
expect_expression_after_operator: unexpected end-of-input; expected an expression after the operator (`RUBY_PARSE_ERROR`) (parser-no-errors)
<!-- Mismatched quotes --> <div class="container'>Content</div>
Attribute value opened with " at (5:11) was never closed. (`UNCLOSED_QUOTE_ERROR`) (parser-no-errors)
Opening tag `<div>` at (5:1) doesn't have a matching closing tag `</div>` in the same scope. (`MISSING_CLOSING_TAG_ERROR`) (parser-no-errors)
<!-- Void element with closing tag --> <img src="image.jpg" alt="Description"></img>
`img` is a void element and should not be used as a closing tag. Use `<img>` or `<img />` instead of `</img>`. (`VOID_ELEMENT_CLOSING_TAG_ERROR`) (parser-no-errors)

References

Released under the MIT License.