| name | code:ruby-tooling |
| description | Ruby linting (standardrb/rubocop), type checking (sorbet), coverage (simplecov), and CI validation.
<example>
Context: User wants to set up linting
user: "configure standardrb for this project"
</example>
<example>
Context: User needs to validate their project
user: "run all checks on this ruby project"
</example>
|
Ruby Tooling
Comprehensive guide to Ruby linting, formatting, type checking, and coverage.
Linting: Standard Ruby (Recommended)
Modern "no config" linting based on RuboCop:
gem 'standard', group: [:development, :test]
Commands
bundle exec standardrb
bundle exec standardrb --fix
bundle exec standardrb --generate-todo
Linting: RuboCop (Classic)
group :development, :test do
gem 'rubocop', '~> 1.60', require: false
gem 'rubocop-rails', require: false
gem 'rubocop-rspec', require: false
gem 'rubocop-performance', require: false
end
Configuration
require:
- rubocop-rails
- rubocop-rspec
- rubocop-performance
AllCops:
NewCops: enable
TargetRubyVersion: 3.3
Exclude:
- 'db/schema.rb'
- 'bin/*'
- 'vendor/**/*'
Metrics/MethodLength:
Max: 20
Metrics/ClassLength:
Max: 200
Metrics/BlockLength:
Exclude:
- 'spec/**/*'
- '*.gemspec'
Style/Documentation:
Enabled: false
Commands
bundle exec rubocop
bundle exec rubocop -a
bundle exec rubocop -A
bundle exec rubocop --auto-gen-config
Type Checking: Sorbet
gem 'sorbet', group: :development
gem 'sorbet-runtime'
gem 'tapioca', group: :development
Setup
bundle exec srb init
bundle exec tapioca init
bundle exec tapioca gems
Commands
bundle exec srb tc
Signatures
class User
extend T::Sig
sig { params(name: String, email: String).void }
def initialize(name:, email:)
@name = name
@email = email
end
sig { returns(String) }
attr_reader :name, :email
end
Type Checking: RBS + Steep
gem 'rbs', group: :development
gem 'steep', group: :development
Commands
bundle exec steep check
bundle exec rbs prototype rb lib/user.rb > sig/user.rbs
Test Coverage: SimpleCov
gem 'simplecov', require: false, group: :test
Configuration
require 'simplecov'
SimpleCov.start do
add_filter '/spec/'
add_filter '/config/'
add_group 'Models', 'app/models'
add_group 'Services', 'app/services'
minimum_coverage 90
end
Commands
bundle exec rspec
open coverage/index.html
All-in-One: Rake Tasks
require 'rspec/core/rake_task'
require 'standard/rake'
RSpec::Core::RakeTask.new(:spec)
desc 'Run all checks'
task check: [:standard, :spec]
desc 'Run checks with autofix'
task fix: ['standard:fix']
task default: :check
Project Validation
Run all checks:
bundle exec standardrb && bundle exec rspec
bundle exec rubocop && bundle exec srb tc && bundle exec rspec
COVERAGE=true bundle exec rspec
CI Configuration
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true
- name: Lint
run: bundle exec standardrb
- name: Type check
run: bundle exec srb tc
- name: Test
run: bundle exec rspec
Quick Reference
| Operation | Standard Ruby | RuboCop |
|---|
| Lint check | standardrb | rubocop |
| Lint fix | standardrb --fix | rubocop -A |
| Type check | srb tc | steep check |
| Format | (included in lint) | (included in lint) |
| Coverage | rspec + simplecov | rspec + simplecov |
| All checks | rake check | rake check |
Quick Validation
One-liner to validate a Ruby project is CI-ready:
bundle exec standardrb && bundle exec srb tc && bundle exec rspec
Recommended Stack
- Lint/Format: Standard Ruby (no config debates)
- Types: Sorbet for new projects
- Testing: RSpec with SimpleCov