It is currently EXPERIMENTAL and pre-release. No support is promised. There may be breaking changes, or we may archive and abandon the repository.
This ruleset integrates linting as a first-class concept under Bazel.
Features:
- No changes needed to rulesets. Works with the Bazel rules you already use.
- No changes needed to BUILD files. You don't need to add lint wrapper macros, and lint doesn't appear in
bazel queryoutput. Instead, users can lint their existing*_librarytargets. - Lints can be presented in various ways:
- a hard failure, like it would with a
lint_testrule that fails the build - as a warning, using whatever reporting method you prefer
- or even as bot code review comments (e.g. with reviewdog)
- a hard failure, like it would with a
How developers use it:
- (preferred) This ruleset provides an Aspect CLI plugin,
so it can register the missing 'lint' command and users just type
bazel lint //path/to:targets. - Run with vanilla Bazel, by placing a couple commands in a shell script, Makefile, or similar wrapper.
See it in action:
This project is inspired by the design for Tricorder. This is how Googlers get their static analysis results in code review (Critique). https://github.com/google/shipshape is an old, abandoned attempt to open-source Tricorder.
Note: we believe that Formatting is NOT Linting. We have a separate project for formatting, see https://github.com/aspect-build/bazel-super-formatter#design
- Protocol Buffers
buf lint: https://buf.build/docs/lint/overview
- JavaScript
eslint: https://eslint.org/
- Python
Please follow the steps in lint/README.md and then send us a PR. Thanks!!
rules_lint currently only works with bzlmod under Bazel 6+. This is because we accumulate dependencies which are difficult to express in a WORKSPACE file. We might add support for WORKSPACE in the future.
Follow instructions from the release you wish to use: https://github.com/aspect-build/rules_lint/releases
Next, you must declare your linters as Bazel aspects.
This is needed because Bazel only allows aspect attributes of type
bool,intorstring. We want to follow the documentation from https://bazel.build/extending/aspects#aspect_definition_2: Aspects are also allowed to have private attributes of types label or label_list. Private label attributes can be used to specify dependencies on tools or libraries that are needed for actions generated by aspects.
We suggest creating a lint.bzl file in whatever package contains most of your
custom Bazel configuration.
This lint.bzl should contain linter aspect declarations.
See the docs/ folder for "aspect factory functions" that declare your linters.
Finally, reference those linters as //path/to:lint.bzl%mylinter
in the lint runner.
If you use the Aspect CLI, then include a block like the following in .aspect/cli/config.yaml:
plugins:
- name: lint-plugin
properties:
lint_aspects:
- //:lint.bzl%eslint
- //:lint.bzl%buf
If you don't use Aspect CLI, you can put these in some other wrapper like a shell script that runs the linter aspects over the requested targets.
See the lint.sh script in the example/ folder.