Erblint::Agent

Template style checking for Ruby projects aimed at AI agents.

Installation

Add this line to your application's Gemfile:

group :development do
  gem 'erb_lint', require: false
  gem 'erblint-agent', require: false
end

And then execute:

bundle install

Usage

Configuration

Require the lint rules from this library. Currently, the only supported way is to add a new file in .erb-linters/erblint_agent.rb with the line:

require 'erblint/agent/linters'

Create or update your .erb-lint.yml configuration file:

---
inherit_gem:
  erblint-agent:
    - config/default.yml
linters:
  Agent::NoDirectSvgTag:
    # message: "Custom error message" # Optional: customize the error message

  Agent::NoDirectEmoji:
    # message: "Custom error message" # Optional: customize the error message

  Agent::NoSpecificClasses:
    forbidden_classes:
      "card": "Use 'CardComponent' instead"

  Agent::NoSpecificAttributes:
    forbidden_attributes:
      "onclick": "Use event listeners instead"

Running the Linters

Run erb-lint with:

bundle exec erb_lint --lint-all

Or check specific files:

bundle exec erb_lint app/views/**/*.erb

Available Linters

Agent::NoDirectSvgTag

Prohibits direct use of SVG tags. Recommends using Tailwind CSS Icons instead.

Configuration:

Agent::NoDirectSvgTag:
  enabled: true
  message: "Custom error message" # Optional: override default message

Bad:

<svg>...</svg>
<svg class="icon" />

Good:

<span class="i-bi-people"></span>

Agent::NoDirectEmoji

Prohibits direct use of Unicode emojis. Recommends using icon classes instead.

Configuration:

Agent::NoDirectEmoji:
  enabled: true
  message: "Custom error message" # Optional: override default message

Bad:

<p>Welcome! 😊</p>

Good:

<p>Welcome! <span class="i-bi-emoji-smile"></span></p>

Agent::NoSpecificClasses

Prohibits the use of specific class names defined in configuration.

Configuration:

Agent::NoSpecificClasses:
  enabled: true
  forbidden_classes:
    "btn-old": "Use 'btn' class instead"
    "text-bold": "Use 'font-bold' instead"

Bad:

<button class="btn-old">Click</button>
<p class="text-bold">Important</p>

Good:

<button class="btn">Click</button>
<p class="font-bold">Important</p>

Agent::NoSpecificAttributes

Prohibits the use of specific HTML attributes defined in configuration.

Configuration:

Agent::NoSpecificAttributes:
  enabled: true
  forbidden_attributes:
    "data-testid": "Use 'data-test-selector' attribute instead"
    "onclick": "Use event listeners instead"

Bad:

<button data-testid="submit-btn">Submit</button>
<div onclick="handleClick()">Click me</div>

Good:

<button data-test-selector="submit-btn">Submit</button>
<div data-action="click->controller#handleClick">Click me</div>

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Erblint::Agent project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.