From 0cd5b9d48db5e31148fdd7ff8775b71883ae40da Mon Sep 17 00:00:00 2001 From: JP Simard Date: Fri, 29 Apr 2022 11:18:08 -0400 Subject: [PATCH] format: add SwiftLint to check-format script This will make it easier to run locally in addition to CI where it's already running. Signed-off-by: JP Simard --- bazel/envoy_mobile_repositories.bzl | 7 +++++++ tools/check_format.sh | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/bazel/envoy_mobile_repositories.bzl b/bazel/envoy_mobile_repositories.bzl index cf5dea57e0..e1f070349a 100644 --- a/bazel/envoy_mobile_repositories.bzl +++ b/bazel/envoy_mobile_repositories.bzl @@ -82,6 +82,13 @@ def swift_repos(): url = "https://github.com/bazelbuild/rules_swift/releases/download/0.27.0/rules_swift.0.27.0.tar.gz", ) + http_archive( + name = "SwiftLint", + build_file_content = """exports_files(["swiftlint"])""", + sha256 = "61d335766a39ba8fa499017a560950bd9fa0b0e5bc318559a9c1c7f4da679256", + url = "https://github.com/realm/SwiftLint/releases/download/0.47.1/portable_swiftlint.zip", + ) + def kotlin_repos(): http_archive( name = "rules_jvm_external", diff --git a/tools/check_format.sh b/tools/check_format.sh index 3e834d83f3..fdab97b616 100755 --- a/tools/check_format.sh +++ b/tools/check_format.sh @@ -8,6 +8,14 @@ if [ -z "$ENVOY_FORMAT_ACTION" ]; then ENVOY_FORMAT_ACTION="check" fi +if [[ $(uname) == "Darwin" ]]; then + if [[ "${ENVOY_FORMAT_ACTION}" == "fix" ]]; then + ./bazelw run --run_under="cd $PWD && " @SwiftLint//:swiftlint -- --fix --quiet 2>/dev/null + else + ./bazelw run --run_under="cd $PWD && " @SwiftLint//:swiftlint -- --strict --quiet 2>/dev/null + fi +fi + TARGET_PATH="$2" # TODO(mattklein123): WORKSPACE is excluded due to warning about @bazel_tools reference. Fix here