Skip to content

Commit 05f561f

Browse files
devversionandrewseguin
authored andcommitted
build: enable buildifier "unsorted-dict-items" and "out-of-order-load" rules (#16857)
Enables the `unsorted-dict-items` rule to enforce that dependencies and more are sorted alphabetically. Additionally enforces that load statements in build files are sorted. Enabling these two rules improves overall health in bazel build files and makes these consistent. (cherry picked from commit aaa656d)
1 parent f76c9af commit 05f561f

File tree

24 files changed

+52
-46
lines changed

24 files changed

+52
-46
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"scripts": {
1616
"postinstall": "ngc -p angular-tsconfig.json",
1717
"build": "gulp build-release-packages",
18-
"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: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,unsorted-dict-items,out-of-order-load",
1919
"bazel:format-lint": "yarn -s bazel:buildifier --lint=warn --mode=check",
2020
"dev-app": "bazel run //src/dev-app:devserver",
2121
"test": "bazel test //src/... --test_tag_filters=-e2e,-browser:firefox-local --build_tag_filters=-browser:firefox-local --build_tests_only",

packages.bzl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ MATERIAL_SCSS_LIBS = [
8080
for p in MATERIAL_PACKAGES
8181
]
8282

83+
GOOGLE_MAPS_PACKAGES = [
84+
"google-map",
85+
]
86+
87+
GOOGLE_MAPS_TARGETS = ["//src/google-maps"] + ["//src/google-maps/%s" % p for p in GOOGLE_MAPS_PACKAGES]
88+
8389
MATERIAL_EXPERIMENTAL_PACKAGES = [
8490
"mdc-button",
8591
"mdc-card",
@@ -109,18 +115,18 @@ MATERIAL_EXPERIMENTAL_SCSS_LIBS = [
109115
ANGULAR_PACKAGE_VERSION = "^8.0.0 || ^9.0.0-0"
110116
MDC_PACKAGE_VERSION = "^1.1.0"
111117
VERSION_PLACEHOLDER_REPLACEMENTS = {
112-
"0.0.0-NG": ANGULAR_PACKAGE_VERSION,
113118
"0.0.0-MDC": MDC_PACKAGE_VERSION,
119+
"0.0.0-NG": ANGULAR_PACKAGE_VERSION,
114120
}
115121

116122
# Base rollup globals for everything in the repo.
117123
ROLLUP_GLOBALS = {
118-
"tslib": "tslib",
119-
"moment": "moment",
120124
"@angular/cdk": "ng.cdk",
121125
"@angular/cdk-experimental": "ng.cdkExperimental",
122126
"@angular/material": "ng.material",
123127
"@angular/material-experimental": "ng.materialExperimental",
128+
"moment": "moment",
129+
"tslib": "tslib",
124130
}
125131

126132
# Rollup globals for cdk subpackages in the form of, e.g., {"@angular/cdk/table": "ng.cdk.table"}

src/cdk-experimental/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_module", "ng_package")
43
load(
54
"//:packages.bzl",
65
"CDK_EXPERIMENTAL_PACKAGES",
76
"CDK_EXPERIMENTAL_TARGETS",
87
"ROLLUP_GLOBALS",
98
)
9+
load("//tools:defaults.bzl", "ng_module", "ng_package")
1010

1111
ng_module(
1212
name = "cdk-experimental",

src/cdk-experimental/scrolling/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite")
43
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
4+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite")
55

66
ng_module(
77
name = "scrolling",

src/cdk-experimental/testing/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_module", "ng_web_test_suite")
43
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
4+
load("//tools:defaults.bzl", "ng_module", "ng_web_test_suite")
55

66
ng_module(
77
name = "testing",

src/e2e-app/BUILD.bazel

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

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
44
load("@npm_bazel_typescript//:defs.bzl", "ts_devserver")
5-
load("//tools:defaults.bzl", "ng_module")
65
load("//:packages.bzl", "ANGULAR_LIBRARY_UMDS")
6+
load("//tools:defaults.bzl", "ng_module")
77

88
exports_files([
99
"protractor.conf.js",

src/material-examples/BUILD.bazel

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,20 @@ package_docs_content(
8282
# in the documentation.
8383
"//guides": "guides",
8484

85-
# For the live-examples in our docs, we want to package the highlighted files
86-
# into the docs content. These will be used to show the source code for examples.
87-
":highlighted-source-files": "examples-highlighted",
88-
89-
# In order to be able to run examples in StackBlitz, we also want to package the
90-
# plain source files into the docs-content.
91-
":example-source-files": "examples-source",
92-
9385
# Package the overviews for "@angular/material" and "@angular/cdk" into the docs content
94-
"//src/material:overviews": "overviews/material",
9586
"//src/cdk:overviews": "overviews/cdk",
87+
"//src/material:overviews": "overviews/material",
9688

9789
# Package the API docs for the Material and CDK package into the docs-content
9890
"//src:api-docs": "api-docs",
91+
92+
# In order to be able to run examples in StackBlitz, we also want to package the
93+
# plain source files into the docs-content.
94+
":example-source-files": "examples-source",
95+
96+
# For the live-examples in our docs, we want to package the highlighted files
97+
# into the docs content. These will be used to show the source code for examples.
98+
":highlighted-source-files": "examples-highlighted",
9999
},
100100
tags = ["docs-package"],
101101
)

src/material-experimental/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_module", "ng_package")
43
load("//:packages.bzl", "ROLLUP_GLOBALS")
4+
load("//tools:defaults.bzl", "ng_module", "ng_package")
55

66
exports_files(["mdc_require_config.js"])
77

src/material-experimental/mdc-button/BUILD.bazel

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

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
4-
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
54
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
5+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
66

77
ng_module(
88
name = "mdc-button",

src/material-experimental/mdc-card/BUILD.bazel

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

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
4-
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module")
54
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
5+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module")
66

77
ng_module(
88
name = "mdc-card",

src/material-experimental/mdc-checkbox/BUILD.bazel

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

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
4-
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
54
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
5+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
66

77
ng_module(
88
name = "mdc-checkbox",

src/material-experimental/mdc-menu/BUILD.bazel

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

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
4-
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
54
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
5+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
66

77
ng_module(
88
name = "mdc-menu",

src/material-experimental/mdc-radio/BUILD.bazel

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

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
4-
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_web_test_suite")
54
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
5+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_web_test_suite")
66

77
ng_module(
88
name = "mdc-radio",

src/material-experimental/mdc-select/BUILD.bazel

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

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
4-
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
54
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
5+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
66

77
ng_module(
88
name = "mdc-select",

src/material-experimental/mdc-sidenav/BUILD.bazel

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

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
4-
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
54
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
5+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
66

77
ng_module(
88
name = "mdc-sidenav",

src/material-experimental/mdc-slide-toggle/BUILD.bazel

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

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
4-
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
54
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
5+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library")
66

77
ng_module(
88
name = "mdc-slide-toggle",

src/material-experimental/mdc-tabs/BUILD.bazel

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

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
4-
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module")
54
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
5+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module")
66

77
ng_module(
88
name = "mdc-tabs",

src/material-moment-adapter/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_module", "ng_package", "ng_test_library", "ng_web_test_suite")
43
load("//:packages.bzl", "ROLLUP_GLOBALS")
4+
load("//tools:defaults.bzl", "ng_module", "ng_package", "ng_test_library", "ng_web_test_suite")
55

66
ng_module(
77
name = "material-moment-adapter",

src/material/BUILD.bazel

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

3-
load("//tools:sass_bundle.bzl", "sass_bundle")
4-
load("//tools:defaults.bzl", "ng_module", "ng_package")
53
load(
64
"//:packages.bzl",
75
"MATERIAL_PACKAGES",
86
"MATERIAL_SCSS_LIBS",
97
"MATERIAL_TARGETS",
108
"ROLLUP_GLOBALS",
119
)
10+
load("//tools:defaults.bzl", "ng_module", "ng_package")
11+
load("//tools:sass_bundle.bzl", "sass_bundle")
1212

1313
# Root "@angular/material" entry-point.
1414
ng_module(

src/material/card/BUILD.bazel

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

33
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library")
4-
load("//tools:defaults.bzl", "markdown_to_html", "ng_e2e_test_library", "ng_module")
54
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite")
5+
load("//tools:defaults.bzl", "markdown_to_html", "ng_e2e_test_library", "ng_module")
66

77
ng_module(
88
name = "card",

tools/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ts_library")
43
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
4+
load("//tools:defaults.bzl", "ts_library")
55

66
ts_library(
77
name = "sass_bundle_lib",

tools/defaults.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
load("@npm_angular_bazel//:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package", _protractor_web_test_suite = "protractor_web_test_suite")
44
load("@npm_bazel_jasmine//:index.bzl", _jasmine_node_test = "jasmine_node_test")
5-
load("@npm_bazel_typescript//:defs.bzl", _ts_library = "ts_library")
65
load("@npm_bazel_karma//:defs.bzl", _karma_web_test_suite = "karma_web_test_suite")
7-
load("//tools/markdown-to-html:index.bzl", _markdown_to_html = "markdown_to_html")
6+
load("@npm_bazel_typescript//:defs.bzl", _ts_library = "ts_library")
87
load("//:packages.bzl", "ANGULAR_LIBRARY_UMDS", "VERSION_PLACEHOLDER_REPLACEMENTS")
8+
load("//tools/markdown-to-html:index.bzl", _markdown_to_html = "markdown_to_html")
99

1010
_DEFAULT_TSCONFIG_BUILD = "//src:bazel-tsconfig-build.json"
1111
_DEFAULT_TSCONFIG_TEST = "//src:tsconfig-test"

tools/dgeni/index.bzl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ dgeni_api_docs = rule(
8282
# { "cdk": ["a11y", "platform", "bidi"] }.
8383
"entry_points": attr.string_list_dict(mandatory = True),
8484

85-
# Dgeni document templates that should be be available as inputs to the
86-
# Bazel action. Dgeni tries to resolve templates from the execroot, so they
87-
# need to be available in the sandbox.
88-
"_dgeni_templates": attr.label(
89-
default = Label("//tools/dgeni/templates"),
90-
),
91-
9285
# NodeJS binary target that runs Dgeni and parses the passed command arguments.
9386
"_dgeni_bin": attr.label(
9487
default = Label("//tools/dgeni"),
9588
executable = True,
9689
cfg = "host",
9790
),
91+
92+
# Dgeni document templates that should be be available as inputs to the
93+
# Bazel action. Dgeni tries to resolve templates from the execroot, so they
94+
# need to be available in the sandbox.
95+
"_dgeni_templates": attr.label(
96+
default = Label("//tools/dgeni/templates"),
97+
),
9898
},
9999
)

tools/sass_bundle.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ sass_bundle = rule(
5050
# the nodejs_binary runs.
5151
"srcs": attr.label_list(allow_files = True),
5252

53+
# The scss entry-point. Note that this uses a label and not a string
54+
# in order to make bazel aware that this file is a *dependency* of the
55+
# rule (and will thus be available to the nodejs_binary in the sandbox).
56+
"entry_point": attr.label(mandatory = True, allow_single_file = True),
57+
5358
# The name of the file to be output from this rule. The rule will fail if
5459
# the nodejs_binary does not produce this output file. By using
5560
# `attr.output()`, we can omit the separate `outputs` declaration a more
5661
# complicated rule would need.
5762
"output_name": attr.output(),
5863

59-
# The scss entry-point. Note that this uses a label and not a string
60-
# in order to make bazel aware that this file is a *dependency* of the
61-
# rule (and will thus be available to the nodejs_binary in the sandbox).
62-
"entry_point": attr.label(mandatory = True, allow_single_file = True),
63-
6464
# The executable (bundler) for this rule (private).
6565
"_sass_bundle": attr.label(
6666
default = Label("//tools:sass_bundle"),

0 commit comments

Comments
 (0)