Skip to content

Commit

Permalink
chore: bring in aspect_rules_lint and add format task to Aspect Workf…
Browse files Browse the repository at this point in the history
…lows (#1390)
  • Loading branch information
gregmagolan authored Dec 8, 2023
1 parent 014b409 commit 69fe0d9
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 3 deletions.
36 changes: 36 additions & 0 deletions .aspect/workflows/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,73 @@ workspaces:
e2e/bzlmod:
icon: bazel
tasks:
format:
without: true
buildifier:
without: true
e2e/js_image_docker:
icon: docker
tasks:
format:
without: true
buildifier:
without: true
e2e/js_image_oci:
icon: linux
tasks:
format:
without: true
buildifier:
without: true
# No test targets. Requires running test.sh.
# - e2e/js_run_devserver:
e2e/npm_link_package:
icon: npm
tasks:
format:
without: true
buildifier:
without: true
e2e/npm_link_package-esm:
icon: npm
tasks:
format:
without: true
buildifier:
without: true
e2e/npm_translate_lock:
icon: npm
tasks:
format:
without: true
buildifier:
without: true
e2e/npm_translate_lock_empty:
icon: npm
tasks:
format:
without: true
buildifier:
without: true
e2e/npm_translate_lock_multi:
icon: npm
tasks:
format:
without: true
buildifier:
without: true
e2e/npm_translate_lock_partial_clone:
icon: npm
tasks:
format:
without: true
buildifier:
without: true
e2e/npm_translate_lock_subdir_patch:
icon: npm
tasks:
format:
without: true
buildifier:
without: true
# Requires an auth token
Expand All @@ -62,41 +82,57 @@ workspaces:
e2e/npm_translate_package_lock:
icon: npm
tasks:
format:
without: true
buildifier:
without: true
e2e/npm_translate_yarn_lock:
icon: yarn
tasks:
format:
without: true
buildifier:
without: true
e2e/package_json_module:
icon: npm
tasks:
format:
without: true
buildifier:
without: true
e2e/pnpm_workspace:
icon: pnpm
tasks:
format:
without: true
buildifier:
without: true
e2e/pnpm_workspace_rerooted:
icon: pnpm
tasks:
format:
without: true
buildifier:
without: true
e2e/rules_foo:
icon: js
tasks:
format:
without: true
buildifier:
without: true
e2e/vendored_node:
icon: js
tasks:
format:
without: true
buildifier:
without: true
# No test targets. Requires running test.sh.
# - e2e/webpack_devserver:
# - e2e/webpack_devserver_esm:
tasks:
format:
soft_fail: false
buildifier:
test:
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ repos:
rev: v0.8.0
hooks:
- id: shellcheck
- repo: local
hooks:
- id: aspect_rules_lint
name: Format
language: system
entry: bazel run //:format
files: .*
5 changes: 5 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ buildifier(
lint_warnings = ["-out-of-order-load"], # TODO: enable out-of-order-load
mode = "diff",
)

alias(
name = "format",
actual = "//tools:format",
)
12 changes: 12 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,22 @@ npm_import(
version = "8.4.0",
)

# Buildifier
load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")

buildifier_prebuilt_deps()

load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")

buildifier_prebuilt_register_toolchains()

# rules_lint
load(
"@aspect_rules_lint//format:repositories.bzl",
"fetch_shfmt",
"fetch_terraform",
)

fetch_shfmt()

fetch_terraform()
11 changes: 8 additions & 3 deletions js/dev_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def rules_js_dev_dependencies():
name = "buildifier_prebuilt",
sha256 = "72b5bb0853aac597cce6482ee6c62513318e7f2c0050bc7c319d75d03d8a3875",
strip_prefix = "buildifier-prebuilt-6.3.3",
urls = [
"https://github.com/keith/buildifier-prebuilt/archive/6.3.3.tar.gz",
],
urls = ["https://github.com/keith/buildifier-prebuilt/archive/6.3.3.tar.gz"],
)

http_archive(
name = "aspect_rules_lint",
sha256 = "604666ec7ffd4f5f2636001ae892a0fbc29c77401bb33dd10601504e3ba6e9a7",
strip_prefix = "rules_lint-0.6.1",
url = "https://github.com/aspect-build/rules_lint/releases/download/v0.6.1/rules_lint-v0.6.1.tar.gz",
)
35 changes: 35 additions & 0 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""BUILD definition for the formatter binary
This is in its own package because it has so many loading-time symbols,
we don't want to trigger eager fetches of these for builds that don't want to run format.
"""

load("@aspect_rules_lint//format:defs.bzl", "multi_formatter_binary")

package(default_visibility = ["//:__subpackages__"])

alias(
name = "shfmt",
actual = select({
"@bazel_tools//src/conditions:darwin_arm64": "@shfmt_darwin_aarch64//file:shfmt",
"@bazel_tools//src/conditions:darwin_x86_64": "@shfmt_darwin_x86_64//file:shfmt",
"@bazel_tools//src/conditions:linux_aarch64": "@shfmt_linux_aarch64//file:shfmt",
"@bazel_tools//src/conditions:linux_x86_64": "@shfmt_linux_x86_64//file:shfmt",
}),
)

alias(
name = "terraform",
actual = select({
"@bazel_tools//src/conditions:darwin_arm64": "@terraform_macos_aarch64//:terraform",
"@bazel_tools//src/conditions:darwin_x86_64": "@terraform_macos_x86_64//:terraform",
"@bazel_tools//src/conditions:linux": "@terraform_linux_x86_64//:terraform",
}),
)

multi_formatter_binary(
name = "format",
go = "@go_sdk//:bin/gofmt",
sh = ":shfmt",
starlark = "@buildifier_prebuilt//:buildifier",
terraform = ":terraform",
)

0 comments on commit 69fe0d9

Please sign in to comment.