cool-easter-32542
07/10/2024, 7:11 AMsrc/project/app.py at some point needed to depend on src/libA/ which is why it was listed among allowed dependencies:
__dependencies_rules__(
(
"src/project/app.py",
[
"//src/libA/**",
"//src/libB/**",
"!*",
],
),
)
However, imagine that over time a decision has been made that this app should not depend on libA and the refactoring was done. The engineer who made the refactoring forgot to update the visibility rules so now they don't really reflect the real restrictions imposed on the app.
Having this rule stale means that someone can again start depending on the libA and the build would pass since the visibility rules are not violated. There should be a way to highlight the presence of stale rules (applies both to dependencies and dependents rules).
Describe the solution you'd like
It might be helpful to make sure that the rules reflect the current state of the dependency graph, i.e. if app.py is said to be allowed to depend on a libA and libB, this should be reflected in the graph, that is, there should be actual dependencies discovered. If that's not the case, a user would get a warning/failure during the build forcing them to keep the visibility rules up-to-date.
It's possible that having visibility rules that don't directly reflect the current state will be acceptable which is why linting for this should be configurable (the usual ignore, warn, error choice perhaps), e.g.
$ pants lint --only=visibility --redundant-rules=warning
Describe alternatives you've considered
This information is currently available via the peek goal:
$ pants peek --include-dep-rules src/project::
and the output can be processed to collect all dependencies of all the modules under a package for which a rule applies and identify whether there are any redundancies in the visibility rules. However, this would require every user to write JSON processing programs whereas this information is readily available in memory when evaluating the visibility rules.
pantsbuild/pants