checkstyle
API for declaring a checkstyle lint aspect that visits java_library rules.
Typical usage:
First, call the fetch_checkstyle
helper in WORKSPACE
to download the jar file.
Alternatively you could use whatever you prefer for managing Java dependencies, such as a Maven integration rule.
Next, declare a binary target for it, typically in tools/lint/BUILD.bazel
:
java_binary(
name = "checkstyle",
main_class = "com.puppycrawl.tools.checkstyle.Main",
runtime_deps = ["@com_puppycrawl_tools_checkstyle"],
)
Finally, declare an aspect for it, typically in tools/lint/linters.bzl
:
load("@aspect_rules_lint//lint:checkstyle.bzl", "checkstyle_aspect")
checkstyle = checkstyle_aspect(
binary = "@@//tools/lint:checkstyle",
config = ["@@//:checkstyle.xml"],
)
Macros and Functions
checkstyle_action
Run Checkstyle as an action under Bazel.
Based on https://checkstyle.sourceforge.io/cmdline.html
Example usage (generated):
load("@aspect_rules_lint//lint:checkstyle.bzl", "checkstyle_action")
checkstyle_action(
# Bazel Rule or Aspect evaluation context
ctx = None,
# label of the the Checkstyle program
executable = None,
# java files to be linted
srcs = [],
# label of the checkstyle.xml file
config = None,
# labels of additional xml files such as suppressions.xml
data = [],
# output file to generate
stdout = None,
)
ctx
Required.
Bazel Rule or Aspect evaluation context
executable
Required.
label of the the Checkstyle program
srcs
Required.
java files to be linted
config
Required.
label of the checkstyle.xml file
data
Required.
labels of additional xml files such as suppressions.xml
stdout
Required.
output file to generate
exit_code
Optional. Default: None
output file to write the exit code. If None, then fail the build when Checkstyle exits non-zero.
options
Optional. Default: []
additional command-line options, see https://checkstyle.sourceforge.io/cmdline.html
lint_checkstyle_aspect
A factory function to create a linter aspect.
Attrs: binary: a Checkstyle executable. Can be obtained from rules_java like so:
```
java_binary(
name = "checkstyle",
main_class = "com.puppycrawl.tools.checkstyle.Main",
# Point to wherever you have the java_import rule defined, see our example
runtime_deps = ["@com_puppycrawl_tools_checkstyle"],
)
```
config: the Checkstyle XML file
Example usage (generated):
load("@aspect_rules_lint//lint:checkstyle.bzl", "lint_checkstyle_aspect")
lint_checkstyle_aspect(
binary = None,
config = None,
)
binary
Required.
config
Required.
data
Optional. Default: []
rule_kinds
Optional. Default: ["java_binary", "java_library"]
fetch_checkstyle
Example usage (generated):
load("@aspect_rules_lint//lint:checkstyle.bzl", "fetch_checkstyle")
fetch_checkstyle(
)