From d9e5286c7f0312d48b8aea7afe86a18bb472e63d Mon Sep 17 00:00:00 2001 From: hvd Date: Mon, 9 Dec 2024 14:43:03 +0100 Subject: [PATCH] Enable warnings for the (formerly) native java rules & symbols --- WARNINGS.md | 133 ++++++++++++++++++++++++++++--- buildifier/config/config_test.go | 48 ++++++++++- buildifier/integration_test.sh | 12 ++- tables/tables.go | 16 +--- warn/docs/warnings.textproto | 102 ++++++++++++++++++++++-- warn/warn.go | 13 ++- warn/warn_bazel_api.go | 31 ++++++- warn/warn_bazel_api_test.go | 49 ++++++++++-- 8 files changed, 354 insertions(+), 50 deletions(-) diff --git a/WARNINGS.md b/WARNINGS.md index a44a6ab46..ceebf1577 100644 --- a/WARNINGS.md +++ b/WARNINGS.md @@ -41,9 +41,19 @@ Warning categories supported by buildifier's linter: * [`native-build`](#native-build) * [`native-cc`](#native-cc) * [`native-cc-proto`](#native-cc-proto) - * [`native-java`](#native-java) + * [`native-java-binary`](#native-java-binary) + * [`native-java-common`](#native-java-common) + * [`native-java-import`](#native-java-import) + * [`native-java-info`](#native-java-info) + * [`native-java-library`](#native-java-library) * [`native-java-lite-proto`](#native-java-lite-proto) + * [`native-java-package-config`](#native-java-package-config) + * [`native-java-plugin`](#native-java-plugin) + * [`native-java-plugin-info`](#native-java-plugin-info) * [`native-java-proto`](#native-java-proto) + * [`native-java-runtime`](#native-java-runtime) + * [`native-java-test`](#native-java-test) + * [`native-java-toolchain`](#native-java-toolchain) * [`native-package`](#native-package) * [`native-proto`](#native-proto) * [`native-proto-common`](#native-proto-common) @@ -713,19 +723,58 @@ The cc_proto_library rule should be loaded from Starlark. -------------------------------------------------------------------------------- -## All Java build rules should be loaded from Starlark +## All Java build rules should be loaded from Starlark - * Category name: `native-java` - * Flag in Bazel: [`--incompatible_load_java_rules_from_bzl`](https://github.com/bazelbuild/bazel/issues/8746) + * Category name: `native-java-binary` + * Flag in Bazel: [`--incompatible_autoload_externally`](https://github.com/bazelbuild/bazel/issues/23043) * Automatic fix: yes - * [Disabled by default](buildifier/README.md#linter) - * [Suppress the warning](#suppress): `# buildifier: disable=native-java` + * [Suppress the warning](#suppress): `# buildifier: disable=native-java-binary` The Java build rules should be loaded from Starlark. -Update: the plans for disabling native rules -[have been postponed](https://groups.google.com/g/bazel-discuss/c/XNvpWcge4AE/m/aJ-aQzszAwAJ), -at the moment it's not required to load Starlark rules. +-------------------------------------------------------------------------------- + +## All Java build rules should be loaded from Starlark + + * Category name: `native-java-common` + * Flag in Bazel: [`--incompatible_autoload_externally`](https://github.com/bazelbuild/bazel/issues/23043) + * Automatic fix: yes + * [Suppress the warning](#suppress): `# buildifier: disable=native-java-common` + +The Java build rules should be loaded from Starlark. + +-------------------------------------------------------------------------------- + +## All Java build rules should be loaded from Starlark + + * Category name: `native-java-import` + * Flag in Bazel: [`--incompatible_autoload_externally`](https://github.com/bazelbuild/bazel/issues/23043) + * Automatic fix: yes + * [Suppress the warning](#suppress): `# buildifier: disable=native-java-import` + +The Java build rules should be loaded from Starlark. + +-------------------------------------------------------------------------------- + +## All Java build rules should be loaded from Starlark + + * Category name: `native-java-info` + * Flag in Bazel: [`--incompatible_autoload_externally`](https://github.com/bazelbuild/bazel/issues/23043) + * Automatic fix: yes + * [Suppress the warning](#suppress): `# buildifier: disable=native-java-info` + +The Java build rules should be loaded from Starlark. + +-------------------------------------------------------------------------------- + +## All Java build rules should be loaded from Starlark + + * Category name: `native-java-library` + * Flag in Bazel: [`--incompatible_autoload_externally`](https://github.com/bazelbuild/bazel/issues/23043) + * Automatic fix: yes + * [Suppress the warning](#suppress): `# buildifier: disable=native-java-library` + +The Java build rules should be loaded from Starlark. -------------------------------------------------------------------------------- @@ -740,6 +789,39 @@ The java_lite_proto_library rule should be loaded from Starlark. -------------------------------------------------------------------------------- +## All Java build rules should be loaded from Starlark + + * Category name: `native-java-package-config` + * Flag in Bazel: [`--incompatible_autoload_externally`](https://github.com/bazelbuild/bazel/issues/23043) + * Automatic fix: yes + * [Suppress the warning](#suppress): `# buildifier: disable=native-java-package-config` + +The Java build rules should be loaded from Starlark. + +-------------------------------------------------------------------------------- + +## All Java build rules should be loaded from Starlark + + * Category name: `native-java-plugin` + * Flag in Bazel: [`--incompatible_autoload_externally`](https://github.com/bazelbuild/bazel/issues/23043) + * Automatic fix: yes + * [Suppress the warning](#suppress): `# buildifier: disable=native-java-plugin` + +The Java build rules should be loaded from Starlark. + +-------------------------------------------------------------------------------- + +## All Java build rules should be loaded from Starlark + + * Category name: `native-java-plugin-info` + * Flag in Bazel: [`--incompatible_autoload_externally`](https://github.com/bazelbuild/bazel/issues/23043) + * Automatic fix: yes + * [Suppress the warning](#suppress): `# buildifier: disable=native-java-plugin-info` + +The Java build rules should be loaded from Starlark. + +-------------------------------------------------------------------------------- + ## java_proto_library rule should be loaded from Starlark * Category name: `native-java-proto` @@ -751,6 +833,39 @@ The java_proto_library rule should be loaded from Starlark. -------------------------------------------------------------------------------- +## All Java build rules should be loaded from Starlark + + * Category name: `native-java-runtime` + * Flag in Bazel: [`--incompatible_autoload_externally`](https://github.com/bazelbuild/bazel/issues/23043) + * Automatic fix: yes + * [Suppress the warning](#suppress): `# buildifier: disable=native-java-runtime` + +The Java build rules should be loaded from Starlark. + +-------------------------------------------------------------------------------- + +## All Java build rules should be loaded from Starlark + + * Category name: `native-java-test` + * Flag in Bazel: [`--incompatible_autoload_externally`](https://github.com/bazelbuild/bazel/issues/23043) + * Automatic fix: yes + * [Suppress the warning](#suppress): `# buildifier: disable=native-java-test` + +The Java build rules should be loaded from Starlark. + +-------------------------------------------------------------------------------- + +## All Java build rules should be loaded from Starlark + + * Category name: `native-java-toolchain` + * Flag in Bazel: [`--incompatible_autoload_externally`](https://github.com/bazelbuild/bazel/issues/23043) + * Automatic fix: yes + * [Suppress the warning](#suppress): `# buildifier: disable=native-java-toolchain` + +The Java build rules should be loaded from Starlark. + +-------------------------------------------------------------------------------- + ## `native.package()` shouldn't be used in .bzl files * Category name: `native-package` diff --git a/buildifier/config/config_test.go b/buildifier/config/config_test.go index 1bba68e9e..82ab3d377 100644 --- a/buildifier/config/config_test.go +++ b/buildifier/config/config_test.go @@ -80,9 +80,19 @@ func ExampleExample() { // "native-build", // "native-cc", // "native-cc-proto", - // "native-java", + // "native-java-binary", + // "native-java-common", + // "native-java-import", + // "native-java-info", + // "native-java-library", // "native-java-lite-proto", + // "native-java-package-config", + // "native-java-plugin", + // "native-java-plugin-info", // "native-java-proto", + // "native-java-runtime", + // "native-java-test", + // "native-java-toolchain", // "native-package", // "native-proto", // "native-proto-common", @@ -268,9 +278,19 @@ func TestValidate(t *testing.T) { "native-build", "native-cc", "native-cc-proto", - "native-java", + "native-java-binary", + "native-java-common", + "native-java-import", + "native-java-info", + "native-java-library", "native-java-lite-proto", + "native-java-package-config", + "native-java-plugin", + "native-java-plugin-info", "native-java-proto", + "native-java-runtime", + "native-java-test", + "native-java-toolchain", "native-package", "native-proto", "native-proto-common", @@ -337,9 +357,19 @@ func TestValidate(t *testing.T) { "native-build", // "native-cc", "native-cc-proto", - // "native-java", + "native-java-binary", + "native-java-common", + "native-java-import", + "native-java-info", + "native-java-library", "native-java-lite-proto", + "native-java-package-config", + "native-java-plugin", + "native-java-plugin-info", "native-java-proto", + "native-java-runtime", + "native-java-test", + "native-java-toolchain", "native-package", "native-proto", "native-proto-common", @@ -405,9 +435,19 @@ func TestValidate(t *testing.T) { // "native-android", "native-build", "native-cc-proto", - // "native-java", + "native-java-binary", + "native-java-common", + "native-java-import", + "native-java-info", + "native-java-library", "native-java-lite-proto", + "native-java-package-config", + "native-java-plugin", + "native-java-plugin-info", "native-java-proto", + "native-java-runtime", + "native-java-test", + "native-java-toolchain", "native-package", "native-proto", "native-proto-common", diff --git a/buildifier/integration_test.sh b/buildifier/integration_test.sh index 4a9d94652..f5457ea44 100755 --- a/buildifier/integration_test.sh +++ b/buildifier/integration_test.sh @@ -285,9 +285,19 @@ cat > golden/.buildifier.example.json <