Skip to content

Commit

Permalink
feat: Set up ktfmt to format code
Browse files Browse the repository at this point in the history
  • Loading branch information
honnix committed Oct 22, 2024
1 parent bd71bc5 commit e48de3d
Show file tree
Hide file tree
Showing 7 changed files with 1,282 additions and 37 deletions.
5 changes: 5 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ alias(
name = "bazel-diff",
actual = "//cli:bazel-diff",
)

alias(
name = "format",
actual = "//cli:format",
)
4 changes: 4 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module(
compatibility_level = 0,
)

bazel_dep(name = "aspect_rules_lint", version = "1.0.2")
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "rules_proto", version = "6.0.0-rc2")
bazel_dep(name = "rules_java", version = "7.6.5")
Expand Down Expand Up @@ -31,3 +32,6 @@ use_repo(
maven,
bazel_diff_maven = "bazel_diff_maven",
)

non_module_repositories = use_extension("//:extension.bzl", "non_module_repositories")
use_repo(non_module_repositories, "ktfmt")
1,258 changes: 1,223 additions & 35 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,17 @@ maven_install(
load("@bazel_diff_maven//:defs.bzl", "pinned_maven_install")

pinned_maven_install()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

aspect_bazel_lib_dependencies()

load(
"@aspect_rules_lint//format:repositories.bzl",
"fetch_ktfmt",
"rules_lint_dependencies",
)

rules_lint_dependencies()

fetch_ktfmt()
16 changes: 14 additions & 2 deletions cli/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@aspect_rules_lint//format:defs.bzl", "format_multirun")
load("@rules_java//java:defs.bzl", "java_binary")
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test")

Expand Down Expand Up @@ -58,7 +59,6 @@ kt_jvm_test(
runtime_deps = [":cli-test-lib"],
)


kt_jvm_test(
name = "SourceFileHasherTest",
data = [
Expand Down Expand Up @@ -106,10 +106,10 @@ kt_jvm_test(

kt_jvm_test(
name = "E2ETest",
data = [":workspaces"],
jvm_flags = ["-Djava.security.manager=allow"],
test_class = "com.bazel_diff.e2e.E2ETest",
runtime_deps = [":cli-test-lib"],
data = [":workspaces"],
)

kt_jvm_test(
Expand Down Expand Up @@ -146,3 +146,15 @@ filegroup(
"src/test/resources/workspaces",
],
)

java_binary(
name = "ktfmt",
main_class = "com.facebook.ktfmt.cli.Main",
runtime_deps = ["@ktfmt//jar"],
)

format_multirun(
name = "format",
kotlin = ":ktfmt",
visibility = ["//visibility:public"],
)
6 changes: 6 additions & 0 deletions extension.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@aspect_rules_lint//format:repositories.bzl", "fetch_ktfmt")

def _non_module_repositories_impl(module_ctx):
fetch_ktfmt()

non_module_repositories = module_extension(_non_module_repositories_impl)
16 changes: 16 additions & 0 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,19 @@ def bazel_diff_dependencies(
sha256 = rules_kotlin_sha,
url = "https://github.com/bazelbuild/rules_kotlin/releases/download/v{version}/rules_kotlin-v{version}.tar.gz".format(version = rules_kotlin_version),
)

_maybe(
http_archive,
name = "aspect_bazel_lib",
sha256 = "6d758a8f646ecee7a3e294fbe4386daafbe0e5966723009c290d493f227c390b",
strip_prefix = "bazel-lib-2.7.7",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.7.7/bazel-lib-v2.7.7.tar.gz",
)

_maybe(
http_archive,
name = "aspect_rules_lint",
sha256 = "7d5feef9ad85f0ba78cc5757a9478f8fa99c58a8cabc1660d610b291dc242e9b",
strip_prefix = "rules_lint-1.0.2",
url = "https://github.com/aspect-build/rules_lint/releases/download/v1.0.2/rules_lint-v1.0.2.tar.gz",
)

0 comments on commit e48de3d

Please sign in to comment.