Allow more things to be marked deprecated through docstrings#1461
Allow more things to be marked deprecated through docstrings#1461adhoc-bobcat wants to merge 3 commits intobazelbuild:mainfrom
Conversation
This change allows module extensions to be marked as deprecated with a docstring comment, so that buildifier emits a warning if they are used. Module extensions can be marked as deprecated in two ways: - When calling the `module_extension` global function to create the extension, through the `doc` argument - Through the docstring of the implementation function. If either docstring contains the text "Deprecated:", buildifier considers the module extension deprecated, and will emit a warning.
This change allows the tag clases defined by module extensions to be marked as deprecated with a docstring comment, so that buildifier emits a warning if they are used. Tag classes are marked as deprecated through the `doc` argument to the `tag_class` global function used to create them.
This change allows rules to be marked as deprecated with a docstring comment, so that buildifier emits a warning if they are used. Rules are considered used when they are referenced during a `load` call from the file where they are defined, or if they are named in a `use_repo_rule` function call. A rule is considered to be any of those constructed by the functions `rule`, `repository_rule`, or `materialzied_rule`. These rules can be marked as deprecated in two ways: - When calling the global function to create the rule, through the `doc` argument - Through the docstring of the implementation function. If either docstring contains the text "Deprecated:", buildifier considers the rule deprecated, and will warn if it is used.
There was a problem hiding this comment.
Code Review
This pull request introduces new linter warnings for deprecated module extensions, module extension tags, and rules. It refactors the existing deprecation warning logic by splitting warn_deprecated.go into specialized files and adds comprehensive integration and unit tests. Documentation in WARNINGS.md and warnings.textproto has been updated to reflect these new categories. I have no feedback to provide.
|
I realized this evening there was something important missing. More complicated Bazel modules implement their rules and extensions privately, and use a re-export pattern, such as: # In a public file
load("//private:impl.bzl", _impl="impl")
impl = _implAs my changes followed the pattern set by the deprecated function warning, the buildifier running on Bazel files that used the "public" version of (And no, I'm not proposing to fix it by recurively scanning. That's pretty obviously not how buildifier is mean to work.) I had some thoughts for how to fix this, and they would simplify the implementation.
Feel free to leave any thoughts here. I'll likely go ahead and implement (2), before removing the draft status I added on this PR. (I don't think it's really that large a change if I need to switch to (1), or even some third option.) |
Buildtools PR checklist
Description
This change allows module extensions and their tags, along with rules to be marked as deprecated so that buildifier emits a warning if they are used.
This is aligned with the existing function deprecation check, where the tool looks for the text "Deprecated:" in the docstring.
Module extensions and rules have two places where they can be marked deprecated.
These changes allow either place to be used.
These changes were tested using the following steps
$ bazelisk test //...