Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions WARNINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Warning categories supported by buildifier's linter:
* [`ctx-actions`](#ctx-actions)
* [`ctx-args`](#ctx-args)
* [`deprecated-function`](#deprecated-function)
* [`deprecated-module-ext`](#deprecated-module-ext)
* [`deprecated-module-ext-tag`](#deprecated-module-ext-tag)
* [`deprecated-rule`](#deprecated-rule)
* [`depset-items`](#depset-items)
* [`depset-iteration`](#depset-iteration)
* [`depset-union`](#depset-union)
Expand Down Expand Up @@ -397,6 +400,44 @@ the [`function-docstring`](#function-docstring) warning.

--------------------------------------------------------------------------------

## <a name="deprecated-module-ext"></a>The module extension is deprecated

* Category name: `deprecated-module-ext`
* Automatic fix: no
* [Suppress the warning](#suppress): `# buildifier: disable=deprecated-module-ext`

The module extension defined in another .bzl file and referenced by a `use_extension`
has a docstring stating that it is deprecated. This is indicated by either the `doc`
argument of the `module_extension` definition function, or the docstring of the
module extension implementation function containing a `Deprecated:` section.

--------------------------------------------------------------------------------

## <a name="deprecated-module-ext-tag"></a>The tag_class from a module extension is deprecated

* Category name: `deprecated-module-ext-tag`
* Automatic fix: no
* [Suppress the warning](#suppress): `# buildifier: disable=deprecated-module-ext-tag`

The module extension defined in another .bzl file has a tag class with a docstring
stating it is deprecated. This is indicated by the `doc` argument to the `tag_class`
function containing a `Deprecated:` section.

--------------------------------------------------------------------------------

## <a name="deprecated-rule"></a>The rule is deprecated

* Category name: `deprecated-rule`
* Automatic fix: no
* [Suppress the warning](#suppress): `# buildifier: disable=deprecated-rule`

The rule defined in another .bzl file and referenced by a `load` or by `use_repo_rule`
has a docstring stating that it is deprecated. This is indicated by either the `doc`
argument of the rule definition function, or the docstring of the rule implementation
function containing a `Deprecated:` section.

--------------------------------------------------------------------------------

## <a name="depset-items"></a>Depset's "items" parameter is deprecated

* Category name: `depset-items`
Expand Down
15 changes: 15 additions & 0 deletions buildifier/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func ExampleExample() {
// "ctx-actions",
// "ctx-args",
// "deprecated-function",
// "deprecated-module-ext",
// "deprecated-module-ext-tag",
// "deprecated-rule",
// "depset-items",
// "depset-iteration",
// "depset-union",
Expand Down Expand Up @@ -280,6 +283,9 @@ func TestValidate(t *testing.T) {
"ctx-actions",
"ctx-args",
"deprecated-function",
"deprecated-module-ext",
"deprecated-module-ext-tag",
"deprecated-rule",
"depset-items",
"depset-iteration",
"depset-union",
Expand Down Expand Up @@ -382,6 +388,9 @@ func TestValidate(t *testing.T) {
"ctx-actions",
"ctx-args",
"deprecated-function",
"deprecated-module-ext",
"deprecated-module-ext-tag",
"deprecated-rule",
"depset-items",
"depset-iteration",
"depset-union",
Expand Down Expand Up @@ -484,6 +493,9 @@ func TestValidate(t *testing.T) {
"ctx-actions",
"ctx-args",
// "deprecated-function",
"deprecated-module-ext",
"deprecated-module-ext-tag",
"deprecated-rule",
"depset-items",
"depset-iteration",
"depset-union",
Expand Down Expand Up @@ -586,6 +598,9 @@ func TestValidate(t *testing.T) {
"ctx-actions",
"ctx-args",
"deprecated-function",
"deprecated-module-ext",
"deprecated-module-ext-tag",
"deprecated-rule",
"depset-items",
"depset-iteration",
"depset-union",
Expand Down
131 changes: 127 additions & 4 deletions buildifier/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ cat > golden/.buildifier.example.json <<EOF
"ctx-actions",
"ctx-args",
"deprecated-function",
"deprecated-module-ext",
"deprecated-module-ext-tag",
"deprecated-rule",
"depset-items",
"depset-iteration",
"depset-union",
Expand Down Expand Up @@ -654,10 +657,10 @@ diff -u json_report ../../golden/json_report_invalid_file_golden || die "$1: wro

cd ../..

# Test the multifile functionality
# Test deprecated functions

mkdir multifile
cd multifile
mkdir -p test_dir/multifile_deprecated_function
cd test_dir/multifile_deprecated_function

cat > lib.bzl <<EOF
def foo():
Expand Down Expand Up @@ -693,7 +696,127 @@ EOF
$buildifier --lint=warn --warnings=deprecated-function BUILD 2> report || ret=$?
diff -u report_golden report || die "$1: wrong console output for multifile warnings (WORKSPACE exists)"

cd ..
cd ../..

# Test that use_extension checks catch a deprecated module extensions

mkdir -p test_dir/deprecated_module_extension
cd test_dir/deprecated_module_extension

cat > ext_dep.bzl <<EOF
def _ext_impl(ctx):
"""
Deprecated:
Use something else.
"""
pass

my_ext = module_extension(implementation = _ext_impl)
EOF

cat > MODULE.bazel <<EOF
my_ext = use_extension("//:ext_dep.bzl", "my_ext")
EOF

cat > report_golden_ext <<EOF
MODULE.bazel:1: deprecated-module-ext: The module extension "my_ext" defined in "//ext_dep.bzl" is deprecated. (https://github.com/bazelbuild/buildtools/blob/main/WARNINGS.md#deprecated-module-ext)
EOF

$buildifier --lint=warn --warnings=deprecated-module-ext MODULE.bazel 2> report || ret=$?
diff -u report_golden_ext report || die "$1: wrong console output for deprecated-module-ext"

cd ../..

# Test that module extension tag use checks catch a deprecated tag_class

mkdir -p test_dir/deprecated_module_extension_tag_class
cd test_dir/deprecated_module_extension_tag_class
cat > ext_tag_dep.bzl <<EOF
def _ext_impl(ctx):
pass

my_ext = module_extension(
implementation = _ext_impl,
tag_classes = {
"tag": tag_class(
doc = "Deprecated: tag is deprecated",
),
},
)
EOF

cat > MODULE.bazel <<EOF
my_ext = use_extension("//:ext_tag_dep.bzl", "my_ext")
my_ext.tag()
EOF

cat > report_golden_tag <<EOF
MODULE.bazel:2: deprecated-module-ext-tag: The tag class "tag" of module extension "my_ext" defined in "//ext_tag_dep.bzl" is deprecated. (https://github.com/bazelbuild/buildtools/blob/main/WARNINGS.md#deprecated-module-ext-tag)
EOF

$buildifier --lint=warn --warnings=deprecated-module-ext-tag MODULE.bazel 2> report || ret=$?
diff -u report_golden_tag report || die "$1: wrong console output for deprecated-module-ext-tag"

cd ../..

# Test that use_repo_rule checks catch a deprecated repository rule

mkdir -p test_dir/deprecated_rule
cd test_dir/deprecated_rule
cat > rules_dep.bzl <<EOF
def _repo_impl(ctx):
"""
Deprecated:
Use something else.
"""
pass

my_repo = repository_rule(implementation = _repo_impl)
EOF

cat > MODULE.bazel <<EOF
use_repo_rule("//:rules_dep.bzl", "my_repo")
EOF

cat > report_golden_repo <<EOF
MODULE.bazel:1: deprecated-rule: The rule "my_repo" defined in "//rules_dep.bzl" is deprecated. (https://github.com/bazelbuild/buildtools/blob/main/WARNINGS.md#deprecated-rule)
EOF

$buildifier --lint=warn --warnings=deprecated-rule MODULE.bazel 2> report || ret=$?
diff -u report_golden_repo report || die "$1: wrong console output for deprecated-rule"

cd ../..

# Test that load checks catch a deprecated rule in a BUILD file

mkdir -p test_dir/deprecated_rule_load
cd test_dir/deprecated_rule_load
cat > rules.bzl <<EOF
def _rule_impl(ctx):
pass

my_rule = rule(
implementation = _rule_impl,
doc = "Deprecated: use something else.",
)
EOF

touch WORKSPACE

cat > BUILD <<EOF
load("//:rules.bzl", "my_rule")

my_rule(name = "foo")
EOF

cat > report_golden_load <<EOF
BUILD:1: deprecated-rule: The rule "my_rule" defined in "//rules.bzl" is deprecated. (https://github.com/bazelbuild/buildtools/blob/main/WARNINGS.md#deprecated-rule)
EOF

$buildifier --lint=warn --warnings=deprecated-rule BUILD 2> report || ret=$?
diff -u report_golden_load report || die "$1: wrong console output for deprecated-rule via load"

cd ../..

# Test allowed symbol load locations

Expand Down
8 changes: 6 additions & 2 deletions warn/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ go_library(
"warn_bazel_operation.go",
"warn_control_flow.go",
"warn_cosmetic.go",
"warn_deprecated.go",
"warn_deprecated_ext.go",
"warn_deprecated_function.go",
"warn_deprecated_rule.go",
"warn_docstring.go",
"warn_load.go",
"warn_macro.go",
Expand Down Expand Up @@ -41,7 +43,9 @@ go_test(
"warn_bazel_test.go",
"warn_control_flow_test.go",
"warn_cosmetic_test.go",
"warn_deprecated_test.go",
"warn_deprecated_ext_test.go",
"warn_deprecated_function_test.go",
"warn_deprecated_rule_test.go",
"warn_docstring_test.go",
"warn_load_test.go",
"warn_macro_test.go",
Expand Down
29 changes: 29 additions & 0 deletions warn/docs/warnings.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,35 @@ warnings: {
"the [`function-docstring`](#function-docstring) warning."
}

warnings: {
name: "deprecated-module-ext"
header: "The module extension is deprecated"
description:
"The module extension defined in another .bzl file and referenced by a `use_extension`\n"
"has a docstring stating that it is deprecated. This is indicated by either the `doc`\n"
"argument of the `module_extension` definition function, or the docstring of the\n"
"module extension implementation function containing a `Deprecated:` section."
}

warnings: {
name: "deprecated-module-ext-tag"
header: "The tag_class from a module extension is deprecated"
description:
"The module extension defined in another .bzl file has a tag class with a docstring\n"
"stating it is deprecated. This is indicated by the `doc` argument to the `tag_class`\n"
"function containing a `Deprecated:` section."
}

warnings: {
name: "deprecated-rule"
header: "The rule is deprecated"
description:
"The rule defined in another .bzl file and referenced by a `load` or by `use_repo_rule`\n"
"has a docstring stating that it is deprecated. This is indicated by either the `doc`\n"
"argument of the rule definition function, or the docstring of the rule implementation\n"
"function containing a `Deprecated:` section."
}

warnings: {
name: "depset-items"
header: "Depset's \"items\" parameter is deprecated"
Expand Down
3 changes: 3 additions & 0 deletions warn/warn.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ var FileWarningMap = map[string]func(f *build.File) []*LinterFinding{
var MultiFileWarningMap = map[string]func(f *build.File, fileReader *FileReader) []*LinterFinding{
"bzl-visibility": bzlVisibilityWarning,
"deprecated-function": deprecatedFunctionWarning,
"deprecated-module-ext": deprecatedModuleExtWarning,
"deprecated-module-ext-tag": deprecatedModuleExtTagWarning,
"deprecated-rule": deprecatedRuleWarning,
"git-repository": nativeGitRepositoryWarning,
"http-archive": nativeHTTPArchiveWarning,
"native-android": nativeAndroidRulesWarning,
Expand Down
Loading