I would like to work on a linter plugin that would...
# general
m
I would like to work on a linter plugin that would verify that dependencies between targets are allowed. For example, our domain layer shouldn't depend on the application layer. Another example, one micro-service should only depend on the contract of another micro-service but not the code. So the idea is to use some kind of wildcard on both sides of the rule. For example:
Copy code
dependency_rule("/modules/core/application/*", allowed=["/modules/core/domain/*"])
What would be the best matching utility within pants for that?
w
I think this has been discussed in two tickets, but I'm less sure of the result for today: https://github.com/pantsbuild/pants/issues/15247 https://github.com/pantsbuild/pants/pull/15803
m
Thanks. I think I have a different approach than 15247 that might work, but I might be wrong. Anyway, I will take a stab at it, an internal plugin at the moment. The visibility approach is interesting as well.
👍 1
h
This is one of our most requested features, so we'd love to see progress here 🙂
One idea is to leverage the existing "tags" mechanism (https://www.pantsbuild.org/docs/reference-target#codetagscode) - any target can be tagged with a list of strings, and you could have logic like "anything tagged with
lib
must not depend on anything tagged with
app
.
Of course that requires adding tags all over the place...
But we've also been toying with the idea of inheriting metadata up the filesystem, so that you could set a default tag in some dir that would apply to all targets in any dir underneath it (unless explicitly overridden)
m
few thoughts: 1. I like the
visibility
feature, but I don't think it covers correctly the different contexts. For example, it make sense for the application layer (e.g
/micro-service-1/application
) to only be visible to the anything within
/micro-service-1/application
, but the contract layer (
/micro-service-1/contract
) cannot and shouldn't know which other micro-services is allowed to consume it. That should be defined at the consumer level. 2. I think inheritance is important here, both for
visibility
and the linter solution. Otherwise to manage it one would have to repeat same configuration over a lot of BUILD files, which is error-prone. 3. I think both visibility field and a linter could cover both contexts.
4. For the linter, instead of inheritance I thought about defining the rules as wild-card to wild-card. The main part I'm missing is the mechanism in pants to retrieve list of targets out of a
/micro-services::
?
@witty-crayon-22786 @happy-kitchen-89482 any idea how to get list of targets from wild card string
micro-services/core::
?
h
Is this string provided as the cmd line specs in the call to
./pants
, or is this a string that appears in a rule definition.
m
the later, yes.
@happy-kitchen-89482 @wide-midnight-78598 please checkout https://github.com/pantsbuild/pants/pull/16446
👀 1