Code Quality & Linters
Relevant source files
The following files were used as context for generating this wiki page:
The Actionmap project employs a multi-layered approach to maintain code quality, spanning Ruby, JavaScript, and HAML source files. By integrating linter execution directly into the RSpec test suite, the project ensures that style violations and potential programmatic errors are treated as test failures, maintaining a high standard for the codebase.
Code quality management is handled through automated linting tools that cover different aspects of the application. These include RuboCop for Ruby code, ESLint for JavaScript, and HAML-Lint for view templates. Additionally, the project uses SimpleCov to track test coverage across the Rails environment.
Sources: spec/linters/eslint_spec.rb, spec/linters/haml_lint_spec.rb, spec/linters/rubocop_spec.rb, spec/rails_helper.rb:4-10
Linter Integration Architecture
The project integrates linting into the standard RSpec testing workflow. Instead of being purely standalone CLI tools, the linters are wrapped in RSpec expectation blocks. This architecture ensures that CI/CD pipelines (such as GitHub Actions) fail if any linting offenses are detected.
The diagram above illustrates how RSpec invokes external shell commands to trigger various linters and validates their output strings to determine test success.
Sources: spec/linters/eslint_spec.rb:6-12, spec/linters/haml_lint_spec.rb:6-11, spec/linters/rubocop_spec.rb:6-9
JavaScript Linting (ESLint)
JavaScript quality is enforced using ESLint, configured primarily through the package.json file and specific devDependencies. The project relies on the Airbnb Base configuration as its foundation.
Configuration and Execution
The linting scope targets all JavaScript files within the app/ and config/ directories.
| Feature | Detail |
|---|---|
| Tool | ESLint ^6.8.0 |
| Base Config | eslint-config-airbnb-base |
| Scripts | lint, lint_fix |
| Target Paths | app/**/*.js, config/**/*.js |
Sources: package.json:32-35, 42-43
The eslint_spec.rb file monitors the output of yarn run lint. A successful run is identified by the terminal output matching the pattern: Done in [time]s..
Sources: spec/linters/eslint_spec.rb:7-12
Ruby and HAML Linting
For the Ruby backend and HAML frontend templates, the project uses RuboCop and HAML-Lint respectively.
RuboCop
RuboCop is executed via bundle exec rubocop. The RSpec wrapper expects the final output to contain the string no offenses detected. Developers can use the -a flag for auto-correction of standard style issues.
Sources: spec/linters/rubocop_spec.rb:6-9
HAML-Lint
HAML templates are inspected using bundle exec haml-lint. The spec verifies that the linter reports 0 lints detected across the inspected files.
Sources: spec/linters/haml_lint_spec.rb:6-11
Test Coverage and Maintenance
The project uses SimpleCov to monitor the effectiveness of the test suite. It is configured to start with the rails profile but explicitly filters out the lib/ directory from coverage reports.
The sequence diagram shows the initialization and data collection flow for code coverage during a test run.
Sources: spec/rails_helper.rb:4-12, features/support/env.rb:13-21
Summary of Linter Commands
| Command | Purpose | Source File |
|---|---|---|
yarn run lint | Runs ESLint on JS files | package.json:42 |
yarn run lint_fix | Automatically fixes ESLint errors | package.json:43 |
bundle exec rubocop | Runs Ruby static analysis | spec/linters/rubocop_spec.rb:7 |
bundle exec haml-lint | Inspects HAML templates | spec/linters/haml_lint_spec.rb:7 |
The integration of these tools ensures that the Actionmap project maintains a consistent style and minimizes common programming errors across its diverse codebase.