Skip to content

Commit 0fc9749

Browse files
chore: install buildifier pre-commit (#310)
Co-authored-by: Yun Peng <[email protected]>
1 parent 151bf39 commit 0fc9749

File tree

71 files changed

+252
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+252
-152
lines changed

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See CONTRIBUTING.md for instructions.
2+
# See https://pre-commit.com for more information
3+
# See https://pre-commit.com/hooks.html for more hooks
4+
5+
# Use a slightly older version of node by default
6+
# as the default uses a very new version of GLIBC
7+
default_language_version:
8+
node: 16.18.0
9+
10+
repos:
11+
# Check formatting and lint for starlark code
12+
- repo: https://github.com/keith/pre-commit-buildifier
13+
rev: 6.3.3
14+
hooks:
15+
- id: buildifier
16+
- id: buildifier-lint
17+
args:
18+
- --warnings=-module-docstring,-provider-params,-name-conventions,-unnamed-macro

android/jetpack-compose/app/src/main/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@build_bazel_rules_android//android:rules.bzl", "android_binary", "android_library")
1+
load("@build_bazel_rules_android//android:rules.bzl", "android_binary")
22
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library")
33

44
kt_android_library(

android/ndk/app/src/main/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@rules_cc//cc:defs.bzl", "cc_library")
21
load("@build_bazel_rules_android//android:rules.bzl", "android_binary", "android_library")
2+
load("@rules_cc//cc:defs.bzl", "cc_library")
33

44
android_library(
55
name = "lib",

bzlmod/02-override_bazel_module/BUILD

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
load("@bazel_skylib//:version.bzl", "hello_msg")
2+
3+
# buildifier: disable=print
24
print(hello_msg)
35

46
cc_binary(
5-
name = "main",
6-
srcs = ["main.cc"],
7-
deps = [
8-
"@lib_a//:lib_a",
9-
"@com_github_google_glog//:glog",
10-
],
7+
name = "main",
8+
srcs = ["main.cc"],
9+
deps = [
10+
"@com_github_google_glog//:glog",
11+
"@lib_a",
12+
],
1113
)

bzlmod/02-override_bazel_module/MODULE.bazel

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,35 @@ module(
44
)
55

66
bazel_dep(name = "glog", version = "0.5.0", repo_name = "com_github_google_glog")
7+
78
# Override glog to a fork version with archive_override.
89
archive_override(
910
module_name = "glog",
10-
urls = ["https://github.com/meteorcloudy/glog/archive/9401faa19e0424791243827b8e95efd3d0d8db23.tar.gz"],
1111
integrity = "sha256-EH4o3n+qkfcsEFODkkRzs1/XAH9ej2V77gv05eplB5k=",
1212
strip_prefix = "glog-9401faa19e0424791243827b8e95efd3d0d8db23",
13+
urls = ["https://github.com/meteorcloudy/glog/archive/9401faa19e0424791243827b8e95efd3d0d8db23.tar.gz"],
1314
)
1415

1516
# Override gflag to a fork version with git_override.
1617
# gflag is still an indirect dependency, the override itself doesn't give the root module visibility on gflags.
1718
git_override(
1819
module_name = "gflags",
19-
remote = "https://github.com/meteorcloudy/gflags.git",
2020
commit = "95995169e86f3fedd19696df5b1811d441c462a2",
21+
remote = "https://github.com/meteorcloudy/gflags.git",
2122
)
2223

2324
# Patch bazel skylib 1.2.0 with a local patch file.
2425
bazel_dep(name = "bazel_skylib", version = "1.2.0")
2526
single_version_override(
2627
module_name = "bazel_skylib",
27-
version = "1.2.0",
28-
patches = ["//:bazel_skylib.patch"],
2928
patch_strip = 1,
29+
patches = ["//:bazel_skylib.patch"],
30+
version = "1.2.0",
3031
)
3132

3233
# Depend on module lib_a at a local path.
3334
# The bazel_dep statement is necessary because the root module must have visibility on lib_a.
34-
bazel_dep(name = "lib_a", version="")
35+
bazel_dep(name = "lib_a", version = "")
3536
local_path_override(
3637
module_name = "lib_a",
3738
path = "./lib_a",

bzlmod/02-override_bazel_module/WORKSPACE

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
21
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
2+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
33

44
# Use a fork version of glog with http_archive.
55
http_archive(
@@ -12,17 +12,17 @@ http_archive(
1212
# Use a fork version of gflags with git_repository.
1313
git_repository(
1414
name = "com_github_gflags_gflags",
15-
remote = "https://github.com/meteorcloudy/gflags.git",
1615
commit = "95995169e86f3fedd19696df5b1811d441c462a2",
16+
remote = "https://github.com/meteorcloudy/gflags.git",
1717
)
1818

1919
# Use a patched version of bazel_skylib
2020
http_archive(
2121
name = "bazel_skylib",
22-
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.0/bazel-skylib-1.2.0.tar.gz"],
23-
sha256 = "af87959afe497dc8dfd4c6cb66e1279cb98ccc84284619ebfec27d9c09a903de",
24-
patches = ["//:bazel_skylib.patch"],
2522
patch_args = ["-p1"],
23+
patches = ["//:bazel_skylib.patch"],
24+
sha256 = "af87959afe497dc8dfd4c6cb66e1279cb98ccc84284619ebfec27d9c09a903de",
25+
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.0/bazel-skylib-1.2.0.tar.gz"],
2626
)
2727

2828
# Depend on lib_a at a local path.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Count how many cities are listed in the file
22
genrule(
33
name = "city_count",
4-
cmd = "wc -l < $< > $@",
5-
outs = ["city_number"],
64
srcs = ["@world_cities//file"],
5+
outs = ["city_number"],
6+
cmd = "wc -l < $< > $@",
77
)
88

99
# Count how many emojis are listed in the file
1010
genrule(
1111
name = "emoji_count",
12-
cmd = "wc -l < $< > $@",
13-
outs = ["emoji_number"],
1412
# To build without --expiremental_enable_bzlmod, this has to be
1513
# srcs = ["@emojis//file"],
1614
srcs = ["@com_foo_bar_emojis//file"],
15+
outs = ["emoji_number"],
16+
cmd = "wc -l < $< > $@",
1717
)

bzlmod/03-introduce_dependencies_with_module_extension/MODULE.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ module(
44
)
55

66
data_deps_ext = use_extension("//:deps.bzl", "data_deps_ext")
7+
78
# The module extension can generate multiple repositories, due to strict deps, you need to declare which ones you need.
89
use_repo(data_deps_ext, "world_cities")
910

1011
# It's fine to declare extension usages before defining module lib_a.
1112
data_deps_ext_from_a = use_extension("@lib_a//:deps.bzl", "data_deps_ext")
13+
1214
# The emojis repo will be accessible with the "com_foo_bar_emojis" repo name instead.
13-
use_repo(data_deps_ext_from_a, com_foo_bar_emojis="emojis")
15+
use_repo(data_deps_ext_from_a, com_foo_bar_emojis = "emojis")
1416

1517
bazel_dep(name = "lib_a", version = "")
1618
local_path_override(

bzlmod/03-introduce_dependencies_with_module_extension/WORKSPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("//:deps.bzl", "world_cities")
2+
23
world_cities()
34

45
# Depend on lib_a at a local path.
@@ -9,4 +10,5 @@ local_repository(
910

1011
# This has to be defined after defining lib_a.
1112
load("@lib_a//:deps.bzl", "emojis")
13+
1214
emojis()

bzlmod/03-introduce_dependencies_with_module_extension/deps.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def world_cities():
77
sha256 = "4d2469729be61b55fcc758ab16bf590196733ff99f1c80e361623decb34ac35d",
88
)
99

10-
def _data_deps_extension_impl(ctx):
10+
def _data_deps_extension_impl(_):
1111
world_cities()
1212

1313
data_deps_ext = module_extension(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
genrule(
22
name = "emoji_count",
3-
cmd = "wc -l < $< > $@",
4-
outs = ["emoji_number"],
53
srcs = ["@emojis//file"],
4+
outs = ["emoji_number"],
5+
cmd = "wc -l < $< > $@",
66
)

bzlmod/04-local_config_and_register_toolchains/MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ module(
55

66
sh_config_ext = use_extension("//:local_config_sh.bzl", "my_sh_config_extension")
77
use_repo(sh_config_ext, "my_local_config_sh")
8+
89
register_toolchains("@my_local_config_sh//:local_sh_toolchain")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
load("//:local_config_sh.bzl", "sh_configure")
2+
23
sh_configure()

bzlmod/04-local_config_and_register_toolchains/local_config_sh.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ def _is_windows(repository_ctx):
44

55
def _my_sh_config_impl(repository_ctx):
66
"""
7-
Detects the path of the shell interpreter via a env var
8-
and stores it in a sh_toolchain rule.
7+
Detects the path of the shell interpreter via a env var.
8+
9+
Stores it in a sh_toolchain rule.
910
"""
1011
sh_path = repository_ctx.os.environ.get("MY_SHELL_BIN_PATH")
1112
if not sh_path:

bzlmod/05-integrate_third_party_package_manager/MODULE.bazel

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ local_path_override(
2727
)
2828

2929
librarian_extension = use_extension("@librarian//:librarian.bzl", "librarian_extension")
30-
31-
librarian_extension.book(name="the_great_gatsby", edition="1995.12")
32-
librarian_extension.book(name="hamlet", edition="2005.1")
30+
librarian_extension.book(
31+
name = "the_great_gatsby",
32+
edition = "1995.12",
33+
)
34+
librarian_extension.book(
35+
name = "hamlet",
36+
edition = "2005.1",
37+
)
3338
use_repo(librarian_extension, "the_great_gatsby")
3439
use_repo(librarian_extension, "hamlet")

bzlmod/05-integrate_third_party_package_manager/WORKSPACE

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ local_repository(
77
name = "librarian",
88
path = "../utils/librarian",
99
)
10+
1011
local_repository(
1112
name = "lib_a",
1213
path = "./lib_a",
1314
)
1415

15-
load("@lib_a//:deps.bzl","fetch_book_for_lib_a")
16-
16+
load("@lib_a//:deps.bzl", "fetch_book_for_lib_a")
1717
load("@librarian//:librarian.bzl", "fetch_book")
18+
1819
fetch_book(
1920
name = "the_great_gatsby",
2021
edition = "1995.12",
@@ -31,7 +32,9 @@ local_repository(
3132
name = "lib_b",
3233
path = "./lib_b",
3334
)
34-
load("@lib_b//:deps.bzl","fetch_book_for_lib_b")
35+
36+
load("@lib_b//:deps.bzl", "fetch_book_for_lib_b")
37+
3538
fetch_book_for_lib_b()
3639

3740
# Answer: You'll get [email protected] and [email protected].

bzlmod/05-integrate_third_party_package_manager/lib_a/MODULE.bazel

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ module(
66
bazel_dep(name = "librarian", version = "")
77

88
librarian_extension = use_extension("@librarian//:librarian.bzl", "librarian_extension")
9-
10-
librarian_extension.book(name="the_great_gatsby", edition="2003.7")
9+
librarian_extension.book(
10+
name = "the_great_gatsby",
11+
edition = "2003.7",
12+
)
1113
use_repo(librarian_extension, "the_great_gatsby")
12-
13-
librarian_extension.book(name="hamlet", edition="1800.1")
14+
librarian_extension.book(
15+
name = "hamlet",
16+
edition = "1800.1",
17+
)
1418
use_repo(librarian_extension, "hamlet")

bzlmod/05-integrate_third_party_package_manager/lib_a/deps.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ load("@librarian//:librarian.bzl", "fetch_book")
22

33
def fetch_book_for_lib_a():
44
fetch_book(
5-
name="the_great_gatsby",
6-
edition="2003.7",
5+
name = "the_great_gatsby",
6+
edition = "2003.7",
77
)
88
fetch_book(
9-
name="hamlet",
10-
edition="1800.1",
9+
name = "hamlet",
10+
edition = "1800.1",
1111
)

bzlmod/05-integrate_third_party_package_manager/lib_b/MODULE.bazel

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ module(
66
bazel_dep(name = "librarian", version = "")
77

88
librarian_extension = use_extension("@librarian//:librarian.bzl", "librarian_extension")
9-
10-
librarian_extension.book(name="the_great_gatsby", edition="2020.5")
9+
librarian_extension.book(
10+
name = "the_great_gatsby",
11+
edition = "2020.5",
12+
)
1113
use_repo(librarian_extension, "the_great_gatsby")
12-
13-
librarian_extension.book(name="hamlet", edition="1603.1")
14+
librarian_extension.book(
15+
name = "hamlet",
16+
edition = "1603.1",
17+
)
1418
use_repo(librarian_extension, "hamlet")

bzlmod/05-integrate_third_party_package_manager/lib_b/deps.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ load("@librarian//:librarian.bzl", "fetch_book")
22

33
def fetch_book_for_lib_b():
44
fetch_book(
5-
name="the_great_gatsby",
6-
edition="2020.5",
5+
name = "the_great_gatsby",
6+
edition = "2020.5",
77
)
88
fetch_book(
9-
name="hamlet",
10-
edition="1603.1",
9+
name = "hamlet",
10+
edition = "1603.1",
1111
)

bzlmod/06-specify_dev_dependency/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("@bazel_skylib//:version.bzl", "version")
22

3+
# buildifier: disable=print
34
print("Bazel Skylib version:", version)
45

56
genrule(

bzlmod/06-specify_dev_dependency/MODULE.bazel

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,22 @@ bazel_dep(
1818
name = "bazel_skylib",
1919
version = "1.1.1",
2020
)
21-
2221
bazel_dep(name = "librarian", version = "")
2322
local_path_override(
2423
module_name = "librarian",
2524
path = "../utils/librarian",
2625
)
2726

2827
librarian_extension = use_extension("@librarian//:librarian.bzl", "librarian_extension")
28+
librarian_extension.book(
29+
name = "the_great_gatsby",
30+
edition = "1995.12",
31+
)
2932

30-
librarian_extension.book(name="the_great_gatsby", edition="1995.12")
3133
# The root module will get [email protected] because [email protected] is only a dev dependency of lib_a.
32-
librarian_extension.book(name="hamlet", edition="1800.1")
33-
34+
librarian_extension.book(
35+
name = "hamlet",
36+
edition = "1800.1",
37+
)
3438
use_repo(librarian_extension, "the_great_gatsby")
3539
use_repo(librarian_extension, "hamlet")

bzlmod/06-specify_dev_dependency/WORKSPACE

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ local_repository(
66
)
77

88
load("@librarian//:librarian.bzl", "fetch_book")
9+
910
fetch_book(
1011
name = "the_great_gatsby",
1112
edition = "1995.12",
1213
)
14+
1315
fetch_book(
1416
name = "hamlet",
1517
edition = "1800.1",
@@ -19,11 +21,13 @@ local_repository(
1921
name = "lib_a",
2022
path = "./lib_a",
2123
)
24+
2225
load("@lib_a//:deps.bzl", "deps")
26+
2327
deps()
2428

2529
http_archive(
2630
name = "bazel_skylib",
27-
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz"],
2831
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
32+
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz"],
2933
)

0 commit comments

Comments
 (0)