-
-
Notifications
You must be signed in to change notification settings - Fork 82
feat: add RuboCop linter support for Ruby #643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Implements RuboCop linter integration for rules_lint, enabling Ruby code linting with support for rb_library, rb_binary, and rb_test targets from rules_ruby. Changes: - Add lint/rubocop.bzl with full RuboCop aspect implementation - rubocop_action() for running RuboCop as a Bazel action - rubocop_fix() for autocorrect support with patch generation - lint_rubocop_aspect() factory function targeting Ruby rule kinds - Support for .rubocop.yml configuration files - SARIF output for machine-readable reports - Color output support via RUBOCOP_FORCE_COLOR - Add rules_ruby integration to example workspace - Add [email protected] dependency to example/MODULE.bazel - Configure Ruby 3.3.0 toolchain - Create rb_library target for example Ruby code - Add example files demonstrating RuboCop - example/src/hello.rb with intentional style violations - example/.rubocop.yml with common RuboCop configuration - example/tools/lint/rubocop_wrapper.sh for RuboCop execution - Add integration tests - rubocop_test in example/test/BUILD.bazel - Test configuration in example/tools/lint/linters.bzl - Update documentation - Add Ruby/RuboCop to main README.md supported tools table - Add bzl_library entry in lint/BUILD.bazel - Comprehensive docstrings with usage examples The implementation follows the same patterns as existing linters (ruff, flake8, eslint) and properly generates both human-readable and machine-readable outputs with exit codes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Replace the simple wrapper script approach with Bundler-based gem management using rules_ruby, following best practices similar to how other linters (flake8, eslint) handle language-specific package managers. Changes: - Add Gemfile and Gemfile.lock with rubocop ~> 1.50 dependency - Configure rules_ruby bundle_fetch in MODULE.bazel to manage gems - Register Ruby toolchains for proper Bazel integration - Replace sh_binary wrapper with alias to @bundle//bin:rubocop - Remove rubocop_wrapper.sh script (no longer needed) - Update rubocop.bzl documentation with Bundler setup instructions - Add --server false flag to disable RuboCop server mode - Add XDG_CACHE_HOME workaround for sandbox cache directory - Wrap all lines to 80 characters for consistency - Redirect stderr to stdout (2>&1) for better error visibility Benefits: - Hermetic builds with pinned gem versions (RuboCop 1.81.1) - Consistent RuboCop versions across all developers - Full integration with Bazel's dependency management - No external Ruby installation required 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
alexeagle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, could you update lint-test.bats also, similar to https://github.com/aspect-build/rules_lint/pull/641/files ?
- Add .ruby-version file specifying jruby-10.0.2.0 - Create java21.bazelrc and update .bazelrc to use Java 21 - Regenerate Gemfile.lock with Java platform support (universal-java) - Add checksums for Java-specific gems (json-2.15.1-java, racc-1.8.1-java) - Update MODULE.bazel and WORKSPACE.bazel to reference .ruby-version - Remove --server false flag from RuboCop invocations (it's the default) JRuby 10 requires Java 21+ and provides Ruby 3.4 compatibility. The Java platform gems avoid C extension compilation issues in Bazel sandbox. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
With the upgrade to Java 21 for JRuby 10 support, java17.bazelrc is no longer referenced and can be removed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
… var RuboCop does not support a RUBOCOP_FORCE_COLOR environment variable. Instead, color output is controlled via the --color command-line flag. Changes: - Add color parameter to rubocop_action() and rubocop_fix() functions - Pass --color flag when color=True - Remove incorrect RUBOCOP_FORCE_COLOR environment variable usage - Pass color option from LintOptionsInfo to action functions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
RuboCop's internal caching provides no benefit in Bazel since: - Bazel caches actions at a higher level based on input hashes - Each action runs in an isolated sandbox with ephemeral directories - The .rubocop_cache directory is discarded after each action Changes: - Add --cache false flag to all RuboCop invocations - Remove cache directory creation (mkdir -p .rubocop_cache) - Remove XDG_CACHE_HOME environment variable management - Simplify shell commands in rubocop_action(), rubocop_fix(), and JSON report generation This makes the code simpler, more efficient, and consistent. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Consolidate duplicated RuboCop command construction logic into a single _build_rubocop_command() helper function. Changes: - Add _build_rubocop_command() to build shell commands with consistent patterns - Use helper in both rubocop_action() and JSON report generation - Fix inconsistency: remove "|| true" pattern, use consistent error handling - Remove unnecessary "touch" command (shell redirect creates the file) - Simplify callers by eliminating manual .format() calls Benefits: - Eliminates code duplication - Ensures consistent command patterns across all RuboCop invocations - Makes future command changes easier to maintain 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add missing progress_message parameter to the machine-readable (JSON) output action for consistency with the human-readable action. This provides better visibility during builds by showing: "Generating machine-readable report for <target> with RuboCop" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Remove the unused env parameter from rubocop_action() and rubocop_fix() since we don't need custom environment variables for RuboCop. Changes: - Remove env parameter from rubocop_action() signature and usage - Remove env parameter from rubocop_fix() signature - Simplify env dict in rubocop_fix() (no longer merging with empty dict) - Remove env argument from all function calls The patcher in rubocop_fix() still gets the JS_BINARY_* environment variables it needs, but we no longer pass around an unnecessary empty dict. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Enhance documentation clarity by: - Making parameter types explicit (File objects, lists, booleans) - Adding examples for Label parameters in lint_rubocop_aspect() - Improving consistency between function docstrings - Adding explanatory comments to JSON args section Changes: - rubocop_action(): Clarify that parameters are File objects and lists - rubocop_fix(): Improve parameter type documentation - lint_rubocop_aspect(): Add concrete examples for binary and configs - JSON args: Add comments explaining why each flag is used This makes the API more understandable and consistent with other linters. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
@alexeagle I think this PR is ready for review. I noticed the |


Summary
Adds support for RuboCop linter for Ruby code in rules_lint, following the established patterns for language-specific linters (similar to flake8 for Python and eslint for JavaScript).
Implementation
Core Features
lint/rubocop.bzl) that visitsrb_binary,rb_library, andrb_testrules--autocorrect-allvia patcher helperRUBOCOP_FORCE_COLORenvironment variableArchitecture
bundle_fetch()to manage RuboCop gem dependenciesJava Runtime Requirements
example/tools/java21.bazelrc)Example Configuration
Gemfile:
.ruby-version:
MODULE.bazel:
tools/lint/linters.bzl:
Testing
example/src/hello.rb)example/test:rubocop(marked manual, expected to fail)example/test/lint_test.batsto verify RuboCop output🤖 Generated with Claude Code