<#21153 Lint visibility rules for stale rule selec...
# github-notifications
c
#21153 Lint visibility rules for stale rule selectors Issue created by AlexTereshenkov Is your feature request related to a problem? Please describe. When declaring visibility rules for build targets, it's possible that a particular selector rule was applicable at the time of definition. E.g.
src/project/app.py
at some point needed to depend on
src/libA/
which is why it was listed among allowed dependencies:
Copy code
__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.
Copy code
$ pants lint --only=visibility --redundant-rules=warning
Describe alternatives you've considered This information is currently available via the
peek
goal:
Copy code
$ 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