Skip to content

Commit

Permalink
refactor: bring linters under rules_multitool (#203)
Browse files Browse the repository at this point in the history
* refactor: bring shellcheck under rules_multitool

BREAKING CHANGE:
you no longer need any fetch_shellcheck calls.
Replace references of a local shellcheck binary with @multitool//tools/shellcheck

* chore: update doc

* refactor: multitool for golangci-lint as well
  • Loading branch information
alexeagle authored Apr 9, 2024
1 parent 2b28a43 commit 5ac8a21
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 195 deletions.
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ bazel_dep(name = "rules_go", version = "0.39.1", repo_name = "io_bazel_rules_go"

multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
multitool.hub(lockfile = "//format:multitool.lock.json")
multitool.hub(lockfile = "//lint:multitool.lock.json")
use_repo(multitool, "multitool")
20 changes: 1 addition & 19 deletions docs/golangci-lint.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 2 additions & 40 deletions docs/shellcheck.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions example/.aspect/cli/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ lint:
- //tools/lint:linters.bzl%eslint
- //tools/lint:linters.bzl%buf
- //tools/lint:linters.bzl%flake8
- //tools/lint:linters.bzl%golangci_lint
- //tools/lint:linters.bzl%pmd
- //tools/lint:linters.bzl%ruff
- //tools/lint:linters.bzl%vale
2 changes: 1 addition & 1 deletion example/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"Bazel dependencies"

bazel_dep(name = "aspect_rules_lint", version = "0.0.0")
bazel_dep(name = "aspect_bazel_lib", version = "2.5.0")
bazel_dep(name = "aspect_bazel_lib", version = "2.6.1")
bazel_dep(name = "aspect_rules_js", version = "1.40.0")
bazel_dep(name = "aspect_rules_ts", version = "2.2.0")
bazel_dep(name = "rules_buf", version = "0.2.0")
Expand Down
13 changes: 4 additions & 9 deletions example/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,6 @@ load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")
# https://github.com/astral-sh/ruff/pull/8631#issuecomment-2022746290
fetch_ruff("v0.3.2")

load("@aspect_rules_lint//lint:golangci-lint.bzl", "fetch_golangci_lint")

fetch_golangci_lint()

load("@aspect_rules_lint//lint:shellcheck.bzl", "fetch_shellcheck")

fetch_shellcheck()

load("@aspect_rules_lint//lint:vale.bzl", "fetch_vale")

fetch_vale()
Expand All @@ -256,5 +248,8 @@ load("@rules_multitool//multitool:multitool.bzl", "multitool")

multitool(
name = "multitool",
lockfile = "@aspect_rules_lint//format:multitool.lock.json",
lockfiles = [
"@aspect_rules_lint//format:multitool.lock.json",
"@aspect_rules_lint//lint:multitool.lock.json",
],
)
8 changes: 0 additions & 8 deletions example/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ load("@aspect_rules_lint//lint:pmd.bzl", "fetch_pmd")

fetch_pmd()

load("@aspect_rules_lint//lint:golangci-lint.bzl", "fetch_golangci_lint")

fetch_golangci_lint()

load("@aspect_rules_lint//lint:shellcheck.bzl", "fetch_shellcheck")

fetch_shellcheck()

load("@aspect_rules_lint//lint:vale.bzl", "fetch_vale")

fetch_vale()
17 changes: 0 additions & 17 deletions example/tools/lint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ we don't want to trigger eager fetches of these for builds that don't want to ru
"""

load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
load("@aspect_rules_lint//lint:shellcheck.bzl", "shellcheck_binary")
load("@aspect_rules_lint//lint:vale_library.bzl", "VALE_STYLES")
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
Expand Down Expand Up @@ -44,19 +43,6 @@ java_binary(
runtime_deps = ["@net_sourceforge_pmd"],
)

native_binary(
name = "golangci_lint",
src = select(
{
"@bazel_tools//src/conditions:linux_x86_64": "@golangci_lint_linux_x86_64//:golangci-lint",
"@bazel_tools//src/conditions:linux_aarch64": "@golangci_lint_linux_aarch64//:golangci-lint",
"@bazel_tools//src/conditions:darwin_x86_64": "@golangci_lint_macos_x86_64//:golangci-lint",
"@bazel_tools//src/conditions:darwin_arm64": "@golangci_lint_macos_aarch64//:golangci-lint",
},
),
out = "golangci-lint",
)

native_binary(
name = "vale",
src = select(
Expand All @@ -82,6 +68,3 @@ copy_to_directory(
],
include_external_repositories = ["vale_*"],
)

# bazel run :shellcheck -- --help
shellcheck_binary(name = "shellcheck")
4 changes: 2 additions & 2 deletions example/tools/lint/linters.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ ruff = lint_ruff_aspect(
ruff_test = lint_test(aspect = ruff)

shellcheck = lint_shellcheck_aspect(
binary = "@@//tools/lint:shellcheck",
binary = "@multitool//tools/shellcheck",
config = "@@//:.shellcheckrc",
)

shellcheck_test = lint_test(aspect = shellcheck)

golangci_lint = lint_golangci_aspect(
binary = "@@//tools/lint:golangci_lint",
binary = "@multitool//tools/golangci-lint",
config = "@@//:.golangci.yaml",
)

Expand Down
11 changes: 1 addition & 10 deletions lint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ bzl_library(
visibility = ["//visibility:public"],
deps = [
"//lint/private:lint_aspect",
"@bazel_skylib//rules:native_binary",
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",
"@io_bazel_rules_go//go:def",
],
)
Expand All @@ -135,13 +132,7 @@ bzl_library(
name = "shellcheck",
srcs = ["shellcheck.bzl"],
visibility = ["//visibility:public"],
deps = [
"//lint/private:lint_aspect",
"//lint/private:maybe",
"@bazel_skylib//rules:native_binary",
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",
],
deps = ["//lint/private:lint_aspect"],
)

bzl_library(
Expand Down
40 changes: 1 addition & 39 deletions lint/golangci-lint.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
load("@aspect_rules_lint//lint:golangci-lint.bzl", "golangci_lint_aspect")
golangci_lint = golangci_lint_aspect(
binary = "@@//tools/lint:golangci_lint",
binary = "@multitool//tools/golangci-lint",
config = "@@//:.golangci.yaml",
)
```
"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@io_bazel_rules_go//go:def.bzl", "go_context")
load("//lint/private:lint_aspect.bzl", "LintOptionsInfo", "filter_srcs", "report_file")

Expand Down Expand Up @@ -103,40 +102,3 @@ def lint_golangci_aspect(binary, config):
},
toolchains = ["@io_bazel_rules_go//go:toolchain"],
)

def fetch_golangci_lint(version = "1.55.2"):
"""Naive macro that fetches a specific version of the golangci-lint from GitHub releases, for commonly-used platforms
Args:
version: must be the default value. In the future this could be honored when we support multiple versions.
"""
if version != "1.55.2":
fail("Only a single version of golangci-lint is currently mirrored. Please file an issue if you need a different version.")
http_archive(
name = "golangci_lint_linux_x86_64",
build_file_content = "exports_files([\"golangci-lint\"])",
strip_prefix = "golangci-lint-{}-linux-amd64".format(version),
sha256 = "ca21c961a33be3bc15e4292dc40c98c8dcc5463a7b6768a3afc123761630c09c",
urls = ["https://github.com/golangci/golangci-lint/releases/download/v{0}/golangci-lint-{0}-linux-amd64.tar.gz".format(version)],
)
http_archive(
name = "golangci_lint_linux_aarch64",
build_file_content = "exports_files([\"golangci-lint\"])",
strip_prefix = "golangci-lint-{}-linux-arm64".format(version),
sha256 = "8eb0cee9b1dbf0eaa49871798c7f8a5b35f2960c52d776a5f31eb7d886b92746",
urls = ["https://github.com/golangci/golangci-lint/releases/download/v{0}/golangci-lint-{0}-linux-arm64.tar.gz".format(version)],
)
http_archive(
name = "golangci_lint_macos_x86_64",
build_file_content = "exports_files([\"golangci-lint\"])",
strip_prefix = "golangci-lint-{}-darwin-amd64".format(version),
sha256 = "632e96e6d5294fbbe7b2c410a49c8fa01c60712a0af85a567de85bcc1623ea21",
urls = ["https://github.com/golangci/golangci-lint/releases/download/v{0}/golangci-lint-{0}-darwin-amd64.tar.gz".format(version)],
)
http_archive(
name = "golangci_lint_macos_aarch64",
build_file_content = "exports_files([\"golangci-lint\"])",
strip_prefix = "golangci-lint-{}-darwin-arm64".format(version),
sha256 = "234463f059249f82045824afdcdd5db5682d0593052f58f6a3039a0a1c3899f6",
urls = ["https://github.com/golangci/golangci-lint/releases/download/v{0}/golangci-lint-{0}-darwin-arm64.tar.gz".format(version)],
)
75 changes: 75 additions & 0 deletions lint/multitool.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"$schema": "https://raw.githubusercontent.com/theoremlp/rules_multitool/main/lockfile.schema.json",
"golangci-lint": {
"binaries": [
{
"os": "linux",
"cpu": "x86_64",
"kind": "archive",
"url": "https://github.com/golangci/golangci-lint/releases/download/v1.55.2/golangci-lint-1.55.2-linux-amd64.tar.gz",
"sha256": "ca21c961a33be3bc15e4292dc40c98c8dcc5463a7b6768a3afc123761630c09c",
"file": "golangci-lint-1.55.2-linux-amd64/golangci-lint"
},
{
"os": "linux",
"cpu": "arm64",
"kind": "archive",
"url": "https://github.com/golangci/golangci-lint/releases/download/v1.55.2/golangci-lint-1.55.2-linux-arm64.tar.gz",
"sha256": "8eb0cee9b1dbf0eaa49871798c7f8a5b35f2960c52d776a5f31eb7d886b92746",
"file": "golangci-lint-1.55.2-linux-arm64/golangci-lint"
},
{
"os": "macos",
"cpu": "x86_64",
"kind": "archive",
"url": "https://github.com/golangci/golangci-lint/releases/download/v1.55.2/golangci-lint-1.55.2-darwin-amd64.tar.gz",
"sha256": "632e96e6d5294fbbe7b2c410a49c8fa01c60712a0af85a567de85bcc1623ea21",
"file": "golangci-lint-1.55.2-darwin-amd64/golangci-lint"
},
{
"os": "macos",
"cpu": "arm64",
"kind": "archive",
"url": "https://github.com/golangci/golangci-lint/releases/download/v1.55.2/golangci-lint-1.55.2-darwin-arm64.tar.gz",
"sha256": "234463f059249f82045824afdcdd5db5682d0593052f58f6a3039a0a1c3899f6",
"file": "golangci-lint-1.55.2-darwin-arm64/golangci-lint"
}
]
},
"shellcheck": {
"binaries": [
{
"kind": "archive",
"os": "macos",
"cpu": "x86_64",
"url": "https://github.com/koalaman/shellcheck/releases/download/v0.10.0/shellcheck-v0.10.0.darwin.x86_64.tar.xz",
"sha256": "ef27684f23279d112d8ad84e0823642e43f838993bbb8c0963db9b58a90464c2",
"file": "shellcheck-v0.10.0/shellcheck"
},
{
"kind": "archive",
"os": "macos",
"cpu": "arm64",
"url": "https://github.com/koalaman/shellcheck/releases/download/v0.10.0/shellcheck-v0.10.0.darwin.aarch64.tar.xz",
"sha256": "bbd2f14826328eee7679da7221f2bc3afb011f6a928b848c80c321f6046ddf81",
"file": "shellcheck-v0.10.0/shellcheck"
},
{
"kind": "archive",
"os": "linux",
"cpu": "arm64",
"url": "https://github.com/koalaman/shellcheck/releases/download/v0.10.0/shellcheck-v0.10.0.linux.aarch64.tar.xz",
"sha256": "324a7e89de8fa2aed0d0c28f3dab59cf84c6d74264022c00c22af665ed1a09bb",
"file": "shellcheck-v0.10.0/shellcheck"
},
{
"kind": "archive",
"os": "linux",
"cpu": "x86_64",
"url": "https://github.com/koalaman/shellcheck/releases/download/v0.10.0/shellcheck-v0.10.0.linux.x86_64.tar.xz",
"sha256": "6c881ab0698e4e6ea235245f22832860544f17ba386442fe7e9d629f8cbedf87",
"file": "shellcheck-v0.10.0/shellcheck"
}
]
}
}
Loading

0 comments on commit 5ac8a21

Please sign in to comment.