Fix Linter Agent

You’ve got linting errors. Red text everywhere. I’ve been there more times than I can count. This agent fixes those violations so you can get back to building.

Approach

Here’s how you tackle this:

  1. Identify your linters - Check Gemfile, package.json, or CI config. Know what you’re dealing with.
  2. Run the linters - See all violations at once. Don’t guess.
  3. Apply auto-fixes where available. Let the tools do the heavy lifting.
  4. Fix remaining errors manually. Some things need a human touch.
  5. Verify clean output - No errors remaining. Zero.
  6. Run tests - Make sure your fixes didn’t break anything.

Ruby Linters & Formatters

RuboCop (Most Common)

This is the standard Ruby linter. You’ll find the config in .rubocop.yml.

# Check violations
bundle exec rubocop

# Auto-fix safe violations
bundle exec rubocop -a

# Auto-fix all (including unsafe)
bundle exec rubocop -A

# Check specific files/directories
bundle exec rubocop app/models/

# Show only offenses (no file list)
bundle exec rubocop --format simple

# Generate TODO file for existing offenses
bundle exec rubocop --auto-gen-config

Standard (Opinionated RuboCop)

Zero-config Ruby style guide. No .rubocop.yml needed. You either love it or you don’t.

# Check violations
bundle exec standardrb

# Auto-fix
bundle exec standardrb --fix

# Check specific files
bundle exec standardrb app/models/user.rb

Syntax Tree (stree)

Ruby formatter and linter with AST-based formatting. Pretty aggressive about its opinions.

# Check formatting
bundle exec stree check app/

# Auto-format
bundle exec stree write app/

# Format specific file
bundle exec stree write app/models/user.rb

ERB/View Linters

ERB Lint (erb_lint gem)

The official ERB linter. Config lives in .erb-lint.yml.

# Check all ERB files
bundle exec erblint --lint-all

# Auto-fix
bundle exec erblint --lint-all --autocorrect

# Check specific files
bundle exec erblint app/views/users/

# Enable all linters
bundle exec erblint --enable-all-linters --lint-all

Herb (Modern ERB Linting)

Newer ERB linter with HTML validation. Worth checking out if erb_lint isn’t cutting it.

# Check ERB files
npx @herb-tools/linter

# Auto-fix
npx @herb-tools/linter --fix

# Format ERB
npx herb-format [path]

# Analyze Ruby in ERB
bundle exec herb analyze .

HTMLBeautifier

Ruby gem for formatting HTML/ERB. Simple but effective.

# Format file
bundle exec htmlbeautifier app/views/users/index.html.erb

# Format all ERB files
find app/views -name "*.erb" -exec bundle exec htmlbeautifier {} \;

Security Scanners

Brakeman

Static security analysis for Rails apps. You should run this regularly. Trust me.

# Run security scan
bundle exec brakeman

# Output to file
bundle exec brakeman -o brakeman-report.html

# Check specific paths
bundle exec brakeman --only-files app/controllers/

# Ignore false positives (uses config/brakeman.ignore)
bundle exec brakeman -i config/brakeman.ignore

Bundler Audit

Checks for vulnerable gem versions. Your dependencies have dependencies, and some of them have security holes.

# Check for vulnerabilities
bundle exec bundle-audit check --update

# Update vulnerability database
bundle exec bundle-audit update

Code Quality Analyzers

Reek

Detects code smells in Ruby. It’s opinionated, but usually right.

# Check all Ruby files
bundle exec reek

# Check specific directory
bundle exec reek app/models/

# Show smell types
bundle exec reek --show-configuration-path

Flay

Finds duplicate code. Copy-paste detection at its finest.

# Find duplicates
bundle exec flay app/

# Set minimum mass threshold
bundle exec flay --mass 20 app/

Flog

Measures code complexity. High scores mean your code is doing too much.

# Check complexity
bundle exec flog app/

# Show details
bundle exec flog -d app/models/

Rails Best Practices

Rails-specific code quality checks. Knows the Rails way better than most developers.

# Run checks
bundle exec rails_best_practices

# Generate config
bundle exec rails_best_practices -g

# Output HTML report
bundle exec rails_best_practices --format html --output-file rbp.html

Database Linters

Strong Migrations

Catches unsafe migrations before they take down your production database. This one has saved me more than once.

# Runs automatically during migrations
bundle exec rails db:migrate

# Check for unsafe operations
bundle exec rails strong_migrations:check

Database Consistency

Validates that database constraints match model validations. Because your database and your code should agree.

bundle exec database_consistency

JavaScript/Frontend (Common in Rails)

ESLint

# Check violations
npx eslint app/javascript/

# Auto-fix
npx eslint app/javascript/ --fix

# Check specific file
npx eslint app/javascript/controllers/users_controller.js

Prettier

# Check formatting
npx prettier --check "app/javascript/**/*.js"

# Auto-fix
npx prettier --write "app/javascript/**/*.js"

# Check multiple file types
npx prettier --check "**/*.{js,jsx,ts,tsx,css,scss,json,md}"

StandardJS

# Check violations
npx standard

# Auto-fix
npx standard --fix

CSS/SCSS Linters

Stylelint

# Check violations
npx stylelint "app/assets/stylesheets/**/*.scss"

# Auto-fix
npx stylelint "app/assets/stylesheets/**/*.scss" --fix

YAML Linters

yamllint

# Check YAML files
yamllint config/

# Check specific file
yamllint config/database.yml

Type Checking

Sorbet

Gradual typing for Ruby. The learning curve is steep, but it catches real bugs.

# Type check
bundle exec srb tc

# Auto-generate RBI files
bundle exec tapioca dsl

# Sync gem signatures
bundle exec tapioca gems

Steep (RBS)

Ruby 3 type checking with RBS. The official approach to Ruby types.

# Type check
bundle exec steep check

# Generate RBS prototypes
bundle exec rbs prototype rb app/models/user.rb

Common CI/Rake Tasks

Many Rails projects combine linters in Rake tasks. Check what’s already there:

# Common patterns
bundle exec rake lint
bundle exec rake lint:fix
bundle exec rake rubocop
bundle exec rake standard
bundle exec rake ci

# Check what's available
bundle exec rake -T | grep -E "(lint|rubocop|standard|check)"

Common Fixes

Style violations:

Naming:

ERB:

Security:


Key Principles

Here’s the thing: linting isn’t about perfection. It’s about consistency.