This document outlines the comprehensive linting and code quality setup for StreamSource.
StreamSource uses a multi-layered approach to code quality:
- Ruby: RuboCop with Rails, Performance, and RSpec extensions
- JavaScript: ESLint with recommended rules + project style config
- Security: Brakeman static analysis
- Editor: EditorConfig for consistent formatting
- Auto-fixing: Automated code style correction
# Run all linting checks
make lint
# Auto-fix all issues
make lint-fix
# Individual linters
make lint-ruby # Ruby only
make lint-js # JavaScript only
make security # Security analysis only
# Code quality metrics
make quality # View project statistics
# Pre-commit validation
make pre-commit # Full validation before commits- File:
.rubocop.yml - Extensions: Rails, Performance, RSpec
- Style: Rails-focused with practical defaults
- Line length: 120 characters
- Method length: 20 lines (excluding tests)
- Class length: 150 lines (excluding tests)
- String literals: Double quotes preferred
- Trailing commas: Required for multi-line structures
bin/**/*- Executable scriptsdb/migrate/**/*- Database migrationsvendor/**/*- Third-party codenode_modules/**/*- JavaScript dependenciescoverage/**/*- Coverage reports
RuboCop can automatically fix many issues:
make lint-fix # Fix all auto-correctable issues
make lint-ruby # Check Ruby issues only- File:
eslint.config.js - Baseline: ESLint recommended + project style rules
- Environment: Browser + ES2022
- Quotes: Single quotes preferred
- Semicolons: Not required
- Indentation: 2 spaces
- No unused variables (except prefixed with
_) - Function spacing: Space before parentheses
Pre-configured for Rails/Hotwire:
StimulusTurboActionCableRails
yarn lint:js:fix # Fix JavaScript issues
make lint-fix # Includes JS auto-fixBrakeman performs static security analysis on Rails applications.
- Total Warnings: 1 (down from 4)
- Fixed Issues: Password regex vulnerability, Format validation issues
- Remaining: Mass assignment warning in Users controller
make security # Quick security scan
make security-detailed # Generate HTML report- Mass Assignment: Review parameter filtering in controllers
- SQL Injection: Use parameterized queries
- XSS: Ensure proper output escaping
- Authentication: Validate JWT tokens properly
Ensures consistent formatting across editors:
- Charset: UTF-8
- Line endings: LF
- Final newline: Required
- Trailing whitespace: Trimmed
- Indentation: 2 spaces for most files
- Ruby (
.rb,.rake,.ru) - JavaScript (
.js,.jsx,.ts,.tsx) - YAML (
.yml,.yaml) - JSON (
.json) - HTML/ERB (
.html,.erb) - CSS/SCSS (
.css,.scss)
The make pre-commit command runs:
- Full test suite
- Ruby code style checks
- Security analysis
- JavaScript linting
Install the pre-commit.com hooks with:
pre-commit install
pre-commit install --hook-type pre-pushUse SKIP_HOOKS=1 to bypass locally when needed.
Recommended CI pipeline:
- name: Code Quality
run: |
make lint
make security
make testRecommended extensions:
- Ruby LSP
- ESLint
- EditorConfig for VS Code
- Better Comments
Built-in support for:
- RuboCop integration
- EditorConfig
- ESLint (with plugin)
make qualityShows:
- Lines of code (Ruby/JavaScript)
- Test coverage percentage
- File counts by type
- Target: >90% test coverage
- Current: 78% (good progress!)
- Focus Areas: Controllers, edge cases
- Ruby: Edit
.rubocop.yml - JavaScript: Edit
eslint.config.js - Security: Configure via Brakeman options
The configuration includes Rails-specific adjustments:
- Longer line lengths for API docs
- Flexible method lengths for controllers
- RSpec-friendly block lengths
- Rails naming conventions
- Run
make pre-committo validate all changes - Address any linting issues
- Ensure security warnings are resolved
- Verify test coverage remains high
- Use
make lint-fixfor quick style fixes - Run individual linters for faster feedback
- Monitor security warnings with
make security - Check metrics periodically with
make quality
Focus on:
- Security implications of changes
- Test coverage for new features
- Adherence to Rails conventions
- Performance impact of changes
- RuboCop Plugin Errors: Ensure gems are installed with
bundle install - ESLint Not Found: Run
yarn installto install JavaScript dependencies - Permission Errors: Ensure Docker container has proper permissions
- Slow Linting: Use individual commands for faster feedback
- Use
make lint-rubyfor Ruby-only checks - Use
make lint-jsfor JavaScript-only checks - Run
make lint-fixto batch auto-corrections - Use parallel execution in CI environments
bundle update rubocop rubocop-rails rubocop-performance rubocop-rspec
yarn upgrade eslint @eslint/js globalsReview and update configurations quarterly:
- New RuboCop cops
- Updated ESLint rules
- Security check improvements
- Performance optimizations
This linting setup ensures consistent, secure, and maintainable code across the StreamSource project.