Skip to content

Linter Rule: Enforce trailing newline

Rule: erb-requires-trailing-newline

Description

This rule enforces that all HTML+ERB template files end with exactly one trailing newline character. This is a formatting convention widely adopted across many languages and tools.

Rationale

Ensuring HTML+ERB files end with a single trailing newline aligns with POSIX conventions, where text files should end with a newline character.

This practice avoids unnecessary diffs from editors or formatters that auto-insert final newlines, improving compatibility with command-line tools and version control systems. It also helps maintain a clean, predictable structure across view files.

Trailing newlines are a common convention in Ruby and are enforced by tools like RuboCop and many Git-based workflows.

Examples

✅ Good

<%= render partial: "header" %>
<%= render partial: "footer" %>

🚫 Bad

erb
<%= render partial: "header" %>
<%= render partial: "footer" %>
File must end with trailing newline (erb-requires-trailing-newline)

References

Released under the MIT License.