diff --git a/docs/ruff.md b/docs/ruff.md
index 065e0862..29f1cfd7 100644
--- a/docs/ruff.md
+++ b/docs/ruff.md
@@ -8,11 +8,46 @@ Typical usage:
load("@aspect_rules_lint//lint:ruff.bzl", "ruff_aspect")
ruff = ruff_aspect(
- binary = "@@//:ruff",
+ binary = "@multitool//tools/ruff",
configs = "@@//:.ruff.toml",
)
```
+## Using a specific ruff version
+
+In `WORKSPACE`, fetch the desired version from https://github.com/astral-sh/ruff/releases
+
+```starlark
+load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")
+
+# Specify a tag from the ruff repository
+fetch_ruff("v0.4.10")
+```
+
+In `tools/lint/BUILD.bazel`, select the tool for the host platform:
+
+```starlark
+alias(
+ name = "ruff",
+ actual = select({
+ "@bazel_tools//src/conditions:linux_x86_64": "@ruff_x86_64-unknown-linux-gnu//:ruff",
+ "@bazel_tools//src/conditions:linux_aarch64": "@ruff_aarch64-unknown-linux-gnu//:ruff",
+ "@bazel_tools//src/conditions:darwin_arm64": "@ruff_aarch64-apple-darwin//:ruff",
+ "@bazel_tools//src/conditions:darwin_x86_64": "@ruff_x86_64-apple-darwin//:ruff",
+ "@bazel_tools//src/conditions:windows_x64": "@ruff_x86_64-pc-windows-msvc//:ruff.exe",
+ }),
+)
+```
+
+Finally, reference this tool alias rather than the one from `@multitool`:
+
+```starlark
+ruff = lint_ruff_aspect(
+ binary = "@@//tools/lint:ruff",
+ ...
+)
+```
+
@@ -45,14 +80,17 @@ Workaround for https://github.com/bazelbuild/bazel/issues/20269
fetch_ruff(tag)
-A repository macro used from WORKSPACE to fetch ruff binaries
+A repository macro used from WORKSPACE to fetch ruff binaries.
+
+Allows the user to select a particular ruff version, rather than get whatever is pinned in the `multitool.lock.json` file.
+
**PARAMETERS**
| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
-| tag | a tag of ruff that we have mirrored, e.g. v0.1.0
| "0.5.0"
|
+| tag | a tag of ruff that we have mirrored, e.g. v0.1.0
| none |
diff --git a/example/WORKSPACE.bazel b/example/WORKSPACE.bazel
index 0652aa82..86c8fd27 100644
--- a/example/WORKSPACE.bazel
+++ b/example/WORKSPACE.bazel
@@ -293,10 +293,6 @@ load("@aspect_rules_lint//lint:pmd.bzl", "fetch_pmd")
fetch_pmd()
-load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")
-
-fetch_ruff()
-
load("@aspect_rules_lint//lint:vale.bzl", "fetch_vale")
fetch_vale()
diff --git a/example/WORKSPACE.bzlmod b/example/WORKSPACE.bzlmod
index 22053dbf..c11ba817 100644
--- a/example/WORKSPACE.bzlmod
+++ b/example/WORKSPACE.bzlmod
@@ -9,7 +9,6 @@ load(
"fetch_ktfmt",
"fetch_swiftformat",
)
-load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")
fetch_java_format()
@@ -17,8 +16,6 @@ fetch_ktfmt()
fetch_swiftformat()
-fetch_ruff()
-
load("@aspect_rules_lint//lint:pmd.bzl", "fetch_pmd")
fetch_pmd()
diff --git a/example/tools/format/BUILD.bazel b/example/tools/format/BUILD.bazel
index ae36f668..43d4a87a 100644
--- a/example/tools/format/BUILD.bazel
+++ b/example/tools/format/BUILD.bazel
@@ -68,7 +68,7 @@ format_multirun(
kotlin = ":ktfmt",
markdown = ":prettier",
protocol_buffer = "//tools/lint:buf",
- python = "//tools/lint:ruff",
+ python = "@aspect_rules_lint//format:ruff",
rust = "@rules_rust//tools/rustfmt:upstream_rustfmt",
scala = ":scalafmt",
shell = "@aspect_rules_lint//format:shfmt",
@@ -96,7 +96,7 @@ format_test(
markdown = ":prettier",
no_sandbox = True, # Enables formatting the entire workspace, paired with 'workspace' attribute
protocol_buffer = "//tools/lint:buf",
- python = "//tools/lint:ruff",
+ python = "@aspect_rules_lint//format:ruff",
scala = ":scalafmt",
sql = ":prettier",
starlark = "@buildifier_prebuilt//:buildifier",
diff --git a/example/tools/lint/BUILD.bazel b/example/tools/lint/BUILD.bazel
index 9d0aa219..638f029c 100644
--- a/example/tools/lint/BUILD.bazel
+++ b/example/tools/lint/BUILD.bazel
@@ -13,17 +13,6 @@ load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_cons
package(default_visibility = ["//:__subpackages__"])
-alias(
- name = "ruff",
- actual = select({
- "@bazel_tools//src/conditions:linux_x86_64": "@ruff_x86_64-unknown-linux-gnu//:ruff",
- "@bazel_tools//src/conditions:linux_aarch64": "@ruff_aarch64-unknown-linux-gnu//:ruff",
- "@bazel_tools//src/conditions:darwin_arm64": "@ruff_aarch64-apple-darwin//:ruff",
- "@bazel_tools//src/conditions:darwin_x86_64": "@ruff_x86_64-apple-darwin//:ruff",
- "@bazel_tools//src/conditions:windows_x64": "@ruff_x86_64-pc-windows-msvc//:ruff.exe",
- }),
-)
-
alias(
name = "buf",
actual = "@rules_buf_toolchains//:buf",
diff --git a/example/tools/lint/linters.bzl b/example/tools/lint/linters.bzl
index 4af3c91d..00177130 100644
--- a/example/tools/lint/linters.bzl
+++ b/example/tools/lint/linters.bzl
@@ -43,7 +43,7 @@ pmd = lint_pmd_aspect(
pmd_test = lint_test(aspect = pmd)
ruff = lint_ruff_aspect(
- binary = "@@//tools/lint:ruff",
+ binary = "@multitool//tools/ruff",
configs = [
"@@//:.ruff.toml",
"@@//src/subdir:ruff.toml",
diff --git a/format/private/formatter_binary.bzl b/format/private/formatter_binary.bzl
index 613c67ce..688f4cbd 100644
--- a/format/private/formatter_binary.bzl
+++ b/format/private/formatter_binary.bzl
@@ -33,6 +33,7 @@ BUILTIN_TOOL_LABELS = {
"Shell": "@multitool//tools/shfmt",
"Terraform": "@multitool//tools/terraform",
"YAML": "@multitool//tools/yamlfmt",
+ "ruff": "@multitool//tools/ruff",
}
# Flags to pass each tool's CLI when running in check mode
diff --git a/lint/multitool.lock.json b/lint/multitool.lock.json
index 18620587..b6134356 100644
--- a/lint/multitool.lock.json
+++ b/lint/multitool.lock.json
@@ -35,5 +35,41 @@
"cpu": "x86_64"
}
]
+ },
+ "ruff": {
+ "binaries": [
+ {
+ "kind": "archive",
+ "url": "https://github.com/astral-sh/ruff/releases/download/0.5.0/ruff-aarch64-apple-darwin.tar.gz",
+ "file": "ruff-aarch64-apple-darwin/ruff",
+ "sha256": "a9203ee067703ef9589cae0d78e3def76e855650d721f77057a3b60638302b36",
+ "os": "macos",
+ "cpu": "arm64"
+ },
+ {
+ "kind": "archive",
+ "url": "https://github.com/astral-sh/ruff/releases/download/0.5.0/ruff-x86_64-unknown-linux-musl.tar.gz",
+ "file": "ruff-x86_64-unknown-linux-musl/ruff",
+ "sha256": "32f4dce258b73f350dd4aab46e7ab54ff74ffb31f3ab2c46e7168f2afd624c78",
+ "os": "linux",
+ "cpu": "x86_64"
+ },
+ {
+ "kind": "archive",
+ "url": "https://github.com/astral-sh/ruff/releases/download/0.5.0/ruff-aarch64-unknown-linux-musl.tar.gz",
+ "file": "ruff-aarch64-unknown-linux-musl/ruff",
+ "sha256": "bc47a3ecff865b38385774fd6191347ecebc201b3a5c0fb56b6e75bc67757ff0",
+ "os": "linux",
+ "cpu": "arm64"
+ },
+ {
+ "kind": "archive",
+ "url": "https://github.com/astral-sh/ruff/releases/download/0.5.0/ruff-x86_64-apple-darwin.tar.gz",
+ "file": "ruff-x86_64-apple-darwin/ruff",
+ "sha256": "283a2d23af7d3b05173e34aade53c4d04694e44ca240b61e5b95c887a379eaf1",
+ "os": "macos",
+ "cpu": "x86_64"
+ }
+ ]
}
}
diff --git a/lint/ruff.bzl b/lint/ruff.bzl
index c28122f6..498f811f 100644
--- a/lint/ruff.bzl
+++ b/lint/ruff.bzl
@@ -6,10 +6,45 @@ Typical usage:
load("@aspect_rules_lint//lint:ruff.bzl", "ruff_aspect")
ruff = ruff_aspect(
- binary = "@@//:ruff",
+ binary = "@multitool//tools/ruff",
configs = "@@//:.ruff.toml",
)
```
+
+## Using a specific ruff version
+
+In `WORKSPACE`, fetch the desired version from https://github.com/astral-sh/ruff/releases
+
+```starlark
+load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")
+
+# Specify a tag from the ruff repository
+fetch_ruff("v0.4.10")
+```
+
+In `tools/lint/BUILD.bazel`, select the tool for the host platform:
+
+```starlark
+alias(
+ name = "ruff",
+ actual = select({
+ "@bazel_tools//src/conditions:linux_x86_64": "@ruff_x86_64-unknown-linux-gnu//:ruff",
+ "@bazel_tools//src/conditions:linux_aarch64": "@ruff_aarch64-unknown-linux-gnu//:ruff",
+ "@bazel_tools//src/conditions:darwin_arm64": "@ruff_aarch64-apple-darwin//:ruff",
+ "@bazel_tools//src/conditions:darwin_x86_64": "@ruff_x86_64-apple-darwin//:ruff",
+ "@bazel_tools//src/conditions:windows_x64": "@ruff_x86_64-pc-windows-msvc//:ruff.exe",
+ }),
+)
+```
+
+Finally, reference this tool alias rather than the one from `@multitool`:
+
+```starlark
+ruff = lint_ruff_aspect(
+ binary = "@@//tools/lint:ruff",
+ ...
+)
+```
"""
load("@bazel_skylib//lib:versions.bzl", "versions")
@@ -195,8 +230,10 @@ ruff_workaround_20269 = repository_rule(
},
)
-def fetch_ruff(tag = RUFF_VERSIONS.keys()[0]):
- """A repository macro used from WORKSPACE to fetch ruff binaries
+def fetch_ruff(tag):
+ """A repository macro used from WORKSPACE to fetch ruff binaries.
+
+ Allows the user to select a particular ruff version, rather than get whatever is pinned in the `multitool.lock.json` file.
Args:
tag: a tag of ruff that we have mirrored, e.g. `v0.1.0`