A Ruby tool to lint ERB and HTML files using built-in and custom linters for code quality and security.
ERB Lint is a Ruby gem that analyzes ERB and HTML template files to detect style violations, security issues, and common errors. It provides a suite of built-in linters for tasks like enforcing safe data interpolation, checking accessibility attributes, and ensuring consistent formatting, helping teams maintain high-quality view code.
Ruby on Rails developers and teams working with ERB templates who need to enforce coding standards, improve security, and ensure consistency across their view layer.
Developers choose ERB Lint for its comprehensive set of Rails-aware linters, extensibility through custom linters, and seamless integration with existing tools like RuboCop, making it a robust solution for template linting without heavy configuration.
Lint your ERB or HTML files
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Linters like ErbSafety mandate safe helpers like .to_json for JavaScript interpolations, directly preventing XSS vulnerabilities as highlighted in the README examples.
The Rubocop linter runs RuboCop rules on Ruby code within ERB templates, allowing consistent style and security checks across view and application code.
Supports custom linters loaded from a .erb_linters directory, enabling teams to write project-specific rules, as demonstrated with the CustomLinter example.
Many linters like RightTrim and NoJavascriptTagHelper offer automatic fixing of violations, reducing manual cleanup effort and enforcing standards quickly.
Linters such as ErbSafety and Rubocop require external config files (.better-html.yml, .rubocop.yml), and errors occur if missing, adding setup complexity.
Tightly coupled to Ruby and ERB templates, making it useless for projects using other languages or frontend frameworks, limiting its versatility.
The README admits that RuboCop rules can trigger false positives in ERB, like Lint/UselessAssignment, due to analyzing each Ruby statement independently.