From 69fe0d9e2690dd36ddfdf17f6fd2b001cae10a0d Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Thu, 7 Dec 2023 23:38:43 -0800 Subject: [PATCH] chore: bring in aspect_rules_lint and add format task to Aspect Workflows (#1390) --- .aspect/workflows/config.yaml | 36 +++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 7 +++++++ BUILD.bazel | 5 +++++ WORKSPACE | 12 ++++++++++++ js/dev_repositories.bzl | 11 ++++++++--- tools/BUILD.bazel | 35 ++++++++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 tools/BUILD.bazel diff --git a/.aspect/workflows/config.yaml b/.aspect/workflows/config.yaml index d08d871a0..143ff73e2 100644 --- a/.aspect/workflows/config.yaml +++ b/.aspect/workflows/config.yaml @@ -6,16 +6,22 @@ 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. @@ -23,36 +29,50 @@ workspaces: 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 @@ -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: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7e7ee97a3..0912b007f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: .* diff --git a/BUILD.bazel b/BUILD.bazel index c8a5c9781..42859daef 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -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", +) diff --git a/WORKSPACE b/WORKSPACE index 43066fc18..780d3c042 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -184,6 +184,7 @@ npm_import( version = "8.4.0", ) +# Buildifier load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps") buildifier_prebuilt_deps() @@ -191,3 +192,14 @@ 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() diff --git a/js/dev_repositories.bzl b/js/dev_repositories.bzl index 139c22ab8..f4d73b03c 100644 --- a/js/dev_repositories.bzl +++ b/js/dev_repositories.bzl @@ -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", ) diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel new file mode 100644 index 000000000..14a474aee --- /dev/null +++ b/tools/BUILD.bazel @@ -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", +)