Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.aspect.build/llms.txt

Use this file to discover all available pages before exploring further.

API for declaring a RuboCop lint aspect that visits rb_binary, rb_library, and rb_test rules. Typical usage:

Installing RuboCop

The recommended approach is to use Bundler with rules_ruby to manage RuboCop as a gem dependency:
  1. Add RuboCop to your Gemfile:
gem "rubocop", "~> 1.50"
  1. Run bundle lock to generate Gemfile.lock
  2. Configure the bundle in your MODULE.bazel:
ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
ruby.toolchain(
    name = "ruby",
    version = "3.3.0",
)
ruby.bundle_fetch(
    name = "bundle",
    gemfile = "//:Gemfile",
    gemfile_lock = "//:Gemfile.lock",
)
use_repo(ruby, "bundle", "ruby", "ruby_toolchains")
  1. Create an alias to the gem-provided binary in tools/lint/BUILD.bazel:
alias(
    name = "rubocop",
    actual = "@bundle//bin:rubocop",
)
  1. Create the linter aspect, typically in tools/lint/linters.bzl:
load("@aspect_rules_lint//lint:rubocop.bzl", "lint_rubocop_aspect")

rubocop = lint_rubocop_aspect(
    binary = "//tools/lint:rubocop",
    configs = ["//:rubocop.yml"],
)
This approach ensures:
  • Hermetic builds with pinned gem versions
  • Consistent RuboCop versions across all developers
  • Integration with Bazel’s dependency management

Configuration

RuboCop will automatically discover .rubocop.yml files according to its standard configuration hierarchy. See https://docs.rubocop.org/rubocop/configuration.html for details. Note: all config files are passed to the action as inputs. This means that a change to any config file invalidates the action cache entries for ALL RuboCop actions.

Function: rubocop_action

Run RuboCop as an action under Bazel. RuboCop will select the configuration file to use for each source file, as documented here: https://docs.rubocop.org/rubocop/configuration.html Note: all config files are passed to the action. This means that a change to any config file invalidates the action cache entries for ALL RuboCop actions. However this is needed because RuboCop’s logic for selecting the appropriate config needs to traverse the directory hierarchy.

Parameters

ctx
unknown
required
Bazel Rule or Aspect evaluation context
executable
unknown
required
File object for the RuboCop executable
srcs
unknown
required
list of File objects for Ruby source files to be linted
config
unknown
required
list of File objects for RuboCop config files (.rubocop.yml)
stdout
unknown
required
File object where linter output will be written
exit_code
unknown
default:"None"
File object where exit code will be written, or None. If None, the build will fail when RuboCop exits non-zero. See https://docs.rubocop.org/rubocop/usage/basic_usage.html
color
unknown
default:"False"
boolean, whether to enable color output
patch
unknown
default:"None"
output file for patch (optional). If provided, uses run_patcher instead of run_shell.

Function: lint_rubocop_aspect

A factory function to create a linter aspect.

Parameters

binary
unknown
required
Label of the RuboCop executable. Example: “//tools/lint:rubocop” or “@bundle//bin:rubocop”
configs
unknown
required
Label or list of Labels of RuboCop config file(s). Example: [”//:rubocop.yml”] or ”//:rubocop.yml”
rule_kinds
unknown
default:"[\"rb_binary\", \"rb_library\", \"rb_test\"]"
list of rule kinds to visit. See https://bazel.build/query/language#kind
filegroup_tags
unknown
default:"[\"ruby\", \"lint-with-rubocop\"]"
list of filegroup tags. Filegroups with these tags will be visited by the aspect in addition to Ruby rule kinds.