New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(linter): add notDependOnLibsWithTags constraint option to enforce-module-boundaries rule #8633
feat(linter): add notDependOnLibsWithTags constraint option to enforce-module-boundaries rule #8633
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/nrwl/nx-dev/B7shm71yXh8gJHUaMcvcUJnRx5kA |
notDependOnLibsWithTags
constraint option to enforce-module-boundaries eslint rule
notDependOnLibsWithTags
constraint option to enforce-module-boundaries eslint rulenotDependOnLibsWithTags
constraint option to enforce-module-boundaries lint rule
@meeroslav can you take a look? We need to make sure that:
|
Fyi, I think failed test is leaking in from upstream code. I can't find a cause locally in this PR. |
@jaytavares thank you for your PR. I think the functionality makes sense, but there are a few things I would change:
Let's say you have the following graph: LIB A(`tag-Angular`) -\
\
LIB B(`tag-Shared`) ---- LIB C(`tag-React-Util`)
LIB D(`tag-React`) --- /
Let's say you want to set up the rule that |
Yeah, try rebasing on to the latest master. That should solve those E2E tests |
d952e11
to
d0acaee
Compare
Are you thinking that we'd require separate config entries? Like this: "depConstraints": [
{
"sourceTag": "scope:tag-A",
"onlyDependOnLibsWithTags": ["scope:tag-A"]
},
{
"sourceTag": "scope:tag-A",
"notDependOnLibsWithTags": [
"scope:tag-B",
]
}
] Rather than a combined syntax like this: "depConstraints": [
{
"sourceTag": "scope:tag-A",
"onlyDependOnLibsWithTags": ["scope:tag-A"]
"notDependOnLibsWithTags": [
"scope:tag-B",
]
}
] |
What I meant was disallowing both. The rule should throw an error if it finds the same If it's ok with you I can add this code to your PR. |
Hmm. Why do you think it's necessary to limit libraries to only one or the other? It seems like it would be more versatile to allow both. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few minor changes. Also, don't forget to add the new property to documentation on https://github.com/nrwl/nx/blob/master/docs/shared/monorepo-tags.md.
If you want, you can skip the documentation and I will add it after your PR is merged.
Ignore the tslint
as that linter is deprecated so we are not supporting it with new features anymore, only bug fixes.
|
||
if (found) return true; | ||
|
||
for (let d of graph.dependencies[projectName] || []) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the recursion all look only at the first level of dependencies. We can always add matrix graphs, similar to circular dependencies if there is ever a need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(More discussion needed, see PR conversation thread)
if ( | ||
constraint.notDependOnLibsWithTags && | ||
hasAnyOfTheseTags( | ||
projectGraph, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not targetProject
like on line 397?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I don't have a full ProjectGraphNode object within the recursive call here.
If this call goes away, we can and should change this to match the similar function signature on line 397. I think there's still some discussion to be had regarding this though. (See PR conversation thread)
Yes, sorry, I was thinking in a single dimension. With multiple tags per project, it makes sense to have both at the same time. Thanks for questioning my proposal. |
Hmm, I get what you're saying; however, I feel like this behavior would be less intuitive. (see below)
With The opposite is true for It really does seem that we need deeper inspection for the latter since we lack the explicitness of the former. As for how we go about that inspection, I'm totally open to suggestions. I modeled my recursive function on the |
The tooling should not compensate for the lack of good hygiene (setting proper tags wherever needed) with running extra checks. If the linter rule is slow, it will drive people to switch it off. That's why recursion is not an option. The whole point of the matrix is to create structure once and keep it in memory, so we don't have to use recursion every time. Finding a path is then a straightforward process. Therefore my suggestion is to finish the PR without using the matrix (or any other in-depth checks). We can add this as an improvement with a follow-up PR. Otherwise, feel free to look at the implementation of the matrix and try to re-use it. |
Hey @jaytavares, just checking in to see if you need help with finishing this PR? The issue with the rule causing the mismatches in IDE is merged in, so you have a clear path to work on this. I can add the function to search for descendants with the given tag using the |
Hey @meeroslav, sorry for the delayed response. I've been busy working on a work project. If you want to implement the search functionality using |
@jaytavares, is it ok if I continue working on your branch? Once this is merged in you would still be marked as author of the PR/commit. |
Sure, go for it. |
Please grant me access rights to your repo so I can rebase and force push master to this branch. |
Done |
631e736
to
a17dcc0
Compare
… to search for disallowed tags in project graph
….spec.ts test files
rename allowedTags & disallowedTags variables for consistency and simplicity
b99dc24
to
c08b25b
Compare
2e6eda6
to
92ae03c
Compare
notDependOnLibsWithTags
constraint option to enforce-module-boundaries lint rule
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Current Behavior
onlyDependOnLibsWithTags
is the only option currently available for setting up tag-based constraints. See #984 for discussion of some limitations this presentsExpected Behavior
Addition of a
notDependOnLibsWithTags
option; provides the ability to prevent the import of a project that contains a disallowed tag.Note: The nature of this option is a bit different than
onlyDependOnLibsWithTags
in that we really want to make sure a library tagged with a disallowed tag doesn't find its way into the source project. For this reason, I coded the implementation with a recursive search for the disallowed tags on all dependent projects.Once I get some confirmation on the above approach, I can finish the remaining tasks:
TODO:
Add tslint implementationRelated Issue(s)
Fixes #984