Skip to content

Commit d463946

Browse files
devversionjosephperrott
authored andcommitted
build: add linting for bazel build files (#16090)
1 parent d0533d8 commit d463946

File tree

106 files changed

+4950
-4176
lines changed

Some content is hidden

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

106 files changed

+4950
-4176
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ jobs:
258258
- *restore_cache
259259
- *yarn_install
260260

261+
- run: ./scripts/circleci/lint-bazel-files.sh
261262
- run: yarn gulp ci:lint
262263

263264
# -------------------------------------------------------------------------------------------

WORKSPACE

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44

55
# Add NodeJS rules (explicitly used for sass bundle rules)
66
http_archive(
7-
name = "build_bazel_rules_nodejs",
8-
sha256 = "1db950bbd27fb2581866e307c0130983471d4c3cd49c46063a2503ca7b6770a4",
9-
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.29.0/rules_nodejs-0.29.0.tar.gz"],
7+
name = "build_bazel_rules_nodejs",
8+
sha256 = "1db950bbd27fb2581866e307c0130983471d4c3cd49c46063a2503ca7b6770a4",
9+
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.29.0/rules_nodejs-0.29.0.tar.gz"],
1010
)
1111

1212
# Add sass rules
1313
http_archive(
14-
name = "io_bazel_rules_sass",
15-
sha256 = "ea79647e5cd36867568d80811a951c7b3170791058f50a5cbd3d542627e78881",
16-
url = "https://github.com/bazelbuild/rules_sass/archive/1.17.3.zip",
17-
strip_prefix = "rules_sass-1.17.3",
14+
name = "io_bazel_rules_sass",
15+
sha256 = "ea79647e5cd36867568d80811a951c7b3170791058f50a5cbd3d542627e78881",
16+
strip_prefix = "rules_sass-1.17.3",
17+
url = "https://github.com/bazelbuild/rules_sass/archive/1.17.3.zip",
1818
)
1919

2020
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install")
@@ -23,73 +23,82 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_reposi
2323
check_bazel_version("0.18.0")
2424

2525
node_repositories(
26-
# For deterministic builds, specify explicit NodeJS and Yarn versions.
27-
node_version = "10.13.0",
28-
# Use latest yarn version to support integrity field (added in yarn 1.10)
29-
yarn_version = "1.12.1",
26+
# For deterministic builds, specify explicit NodeJS and Yarn versions.
27+
node_version = "10.13.0",
28+
# Use latest yarn version to support integrity field (added in yarn 1.10)
29+
yarn_version = "1.12.1",
3030
)
3131

3232
yarn_install(
33-
name = "npm",
34-
package_json = "//:package.json",
35-
# Ensure that the script is available when running `postinstall` in the Bazel sandbox.
36-
data = [
37-
"//:tools/npm/check-npm.js",
38-
"//:angular-tsconfig.json",
39-
],
40-
yarn_lock = "//:yarn.lock",
33+
name = "npm",
34+
# Ensure that the script is available when running `postinstall` in the Bazel sandbox.
35+
data = [
36+
"//:angular-tsconfig.json",
37+
"//:tools/npm/check-npm.js",
38+
],
39+
package_json = "//:package.json",
40+
yarn_lock = "//:yarn.lock",
4141
)
4242

4343
# Install all bazel dependencies of the @ngdeps npm packages
4444
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
45+
4546
install_bazel_dependencies()
4647

4748
# Setup TypeScript Bazel workspace
4849
load("@npm_bazel_typescript//:defs.bzl", "ts_setup_workspace")
50+
4951
ts_setup_workspace()
5052

5153
# Fetch transitive dependencies which are needed to use the karma rules.
5254
load("@npm_bazel_karma//:package.bzl", "rules_karma_dependencies")
55+
5356
rules_karma_dependencies()
5457

5558
# Setup web testing. We need to setup a browser because the web testing rules for TypeScript need
5659
# a reference to a registered browser (ideally that's a hermetic version of a browser)
5760
load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")
61+
5862
web_test_repositories()
5963

6064
load("@npm_bazel_karma//:browser_repositories.bzl", "browser_repositories")
65+
6166
browser_repositories()
6267

6368
# Fetch transitive dependencies which are needed to use the Sass rules.
6469
load("@io_bazel_rules_sass//:package.bzl", "rules_sass_dependencies")
70+
6571
rules_sass_dependencies()
6672

6773
# Setup the Sass rule repositories.
6874
load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories")
75+
6976
sass_repositories()
7077

7178
# Bring in bazel_toolchains for RBE setup configuration.
7279
http_archive(
73-
name = "bazel_toolchains",
74-
sha256 = "67335b3563d9b67dc2550b8f27cc689b64fadac491e69ce78763d9ba894cc5cc",
75-
strip_prefix = "bazel-toolchains-cddc376d428ada2927ad359211c3e356bd9c9fbb",
76-
url = "https://github.com/bazelbuild/bazel-toolchains/archive/cddc376d428ada2927ad359211c3e356bd9c9fbb.tar.gz",
80+
name = "bazel_toolchains",
81+
sha256 = "67335b3563d9b67dc2550b8f27cc689b64fadac491e69ce78763d9ba894cc5cc",
82+
strip_prefix = "bazel-toolchains-cddc376d428ada2927ad359211c3e356bd9c9fbb",
83+
url = "https://github.com/bazelbuild/bazel-toolchains/archive/cddc376d428ada2927ad359211c3e356bd9c9fbb.tar.gz",
7784
)
7885

7986
load("@bazel_toolchains//repositories:repositories.bzl", bazel_toolchains_repositories = "repositories")
87+
8088
bazel_toolchains_repositories()
8189

8290
load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig")
91+
8392
rbe_autoconfig(
84-
name = "rbe_default",
85-
# We can't use the default "ubuntu16_04" RBE image provided by the autoconfig because we need
86-
# a specific Linux kernel that comes with "libx11" in order to run headless browser tests.
87-
repository = "asci-toolchain/nosla-ubuntu16_04-webtest",
88-
registry = "gcr.io",
89-
digest = "sha256:e874885f5e3d9ac0c0d3176e5369cb5969467dbf9ad8d42b862829cec8d84b9b",
90-
# Need to specify a base container digest in order to ensure that we can use the checked-in
91-
# platform configurations for the "ubuntu16_04" image. Otherwise the autoconfig rule would
92-
# need to pull the image and run it in order determine the toolchain configuration.
93-
# See: https://github.com/bazelbuild/bazel-toolchains/blob/master/rules/rbe_repo.bzl#L229
94-
base_container_digest = "sha256:da0f21c71abce3bbb92c3a0c44c3737f007a82b60f8bd2930abc55fe64fc2729",
93+
name = "rbe_default",
94+
# Need to specify a base container digest in order to ensure that we can use the checked-in
95+
# platform configurations for the "ubuntu16_04" image. Otherwise the autoconfig rule would
96+
# need to pull the image and run it in order determine the toolchain configuration.
97+
# See: https://github.com/bazelbuild/bazel-toolchains/blob/master/rules/rbe_repo.bzl#L229
98+
base_container_digest = "sha256:da0f21c71abce3bbb92c3a0c44c3737f007a82b60f8bd2930abc55fe64fc2729",
99+
digest = "sha256:e874885f5e3d9ac0c0d3176e5369cb5969467dbf9ad8d42b862829cec8d84b9b",
100+
registry = "gcr.io",
101+
# We can't use the default "ubuntu16_04" RBE image provided by the autoconfig because we need
102+
# a specific Linux kernel that comes with "libx11" in order to run headless browser tests.
103+
repository = "asci-toolchain/nosla-ubuntu16_04-webtest",
95104
)

guides/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package(default_visibility=["//visibility:public"])
1+
package(default_visibility = ["//visibility:public"])
22

33
load("//tools:defaults.bzl", "markdown_to_html")
44

55
markdown_to_html(
6-
name = "guides",
7-
srcs = glob(["**/*.md"]),
6+
name = "guides",
7+
srcs = glob(["**/*.md"]),
88
)

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
"scripts": {
1515
"postinstall": "ngc -p angular-tsconfig.json",
1616
"build": "gulp build-release-packages",
17+
"bazel:buildifier": "find . -type f \\( -name \"*.bzl\" -or -name WORKSPACE -or -name BUILD -or -name BUILD.bazel \\) ! -path \"*/node_modules/*\" | xargs buildifier -v --warnings=attr-cfg,attr-license,attr-non-empty,attr-output-default,attr-single-file,constant-glob,ctx-args,depset-iteration,depset-union,dict-concatenation,duplicated-name,filetype,git-repository,http-archive,integer-division,load,load-on-top,native-build,native-package,output-group,package-name,package-on-top,redefined-variable,repository-name,same-origin-load,string-iteration,unused-variable",
18+
"bazel:format-lint": "yarn -s bazel:buildifier --lint=warn --mode=check",
1719
"dev-app": "gulp serve:devapp",
1820
"test": "bazel test //src/... --test_tag_filters=-e2e",
19-
"lint": "gulp lint",
21+
"lint": "gulp lint && yarn -s bazel:format-lint",
2022
"e2e": "bazel test //src/... --test_tag_filters=e2e",
2123
"deploy": "gulp deploy:devapp",
2224
"webdriver-manager": "webdriver-manager",
@@ -26,7 +28,9 @@
2628
"publish-release": "ts-node --project tools/release/ tools/release/publish-release.ts",
2729
"check-release-output": "ts-node --project tools/release tools/release/check-release-output.ts",
2830
"preinstall": "node ./tools/npm/check-npm.js",
29-
"format": "git-clang-format HEAD $(git diff HEAD --name-only | grep -v \"\\.d\\.ts\")"
31+
"format:ts": "git-clang-format HEAD $(git diff HEAD --name-only | grep -v \"\\.d\\.ts\")",
32+
"format:bazel": "yarn -s bazel:buildifier --lint=fix --mode=fix",
33+
"format": "yarn -s format:ts && yarn -s format:bazel"
3034
},
3135
"version": "8.0.0",
3236
"requiredAngularVersion": "^8.0.0 || ^9.0.0-0",
@@ -39,6 +43,7 @@
3943
"@angular/elements": "^8.0.0",
4044
"@angular/forms": "^8.0.0",
4145
"@angular/platform-browser": "^8.0.0",
46+
"@bazel/buildifier": "^0.25.1",
4247
"@webcomponents/custom-elements": "^1.1.0",
4348
"core-js": "^2.6.1",
4449
"material-components-web": "^1.1.0",

0 commit comments

Comments
 (0)