realvizu / NsDepCop

NsDepCop is a static code analysis tool that helps to enforce namespace dependency rules in C# projects. No more unplanned or unnoticed dependencies in your system.
GNU General Public License v2.0
199 stars 32 forks source link

Disallowed from a.* to a.b.* causes a.b.c->a.b.c to throw a warning #49

Open destects opened 5 years ago

destects commented 5 years ago

ChildCanDependOnParentImplicitly="true" and

Will cause any references between the Core.Something.SubSomething namespace (and it's children) to Core.Something.SubSomething.* namespaces to throw an illegal namespace warning.

And also, Core.Something.SubSomething.Things1 namespace should be able to reference Core.Something.SubSomething.Thing2 namespace without issue. but a lateral reference is not allowed. and since Disallowed is stronger than Allowed, the lateral movement is reported as an illegal reference.

realvizu commented 5 years ago

Sorry, I don't understand your issue clearly.

I've just created a unit test for the situation that you've described in the issue title but I cannot reproduce the problem. https://github.com/realvizu/NsDepCop/blob/e56565c905adaa8bd831d3e7eb64655db5bbce83/source/NsDepCop.Core.Test/Implementation/Analysis/TypeDependencyValidatorTests.cs#L123-L130

Also, the implementation of the TypeDependencyValidator explicitly starts with allowing all same-namespace references, so a.b.c->a.b.c should not throw a warning. https://github.com/realvizu/NsDepCop/blob/e56565c905adaa8bd831d3e7eb64655db5bbce83/source/NsDepCop.Core/Implementation/Analysis/TypeDependencyValidator.cs#L32-L36

So could you give me a complete example so I can reproduce your problem?

realvizu commented 5 years ago

Oh, I think I understand now. So your problem is that a disallowed rule is stronger than the ChildCanDependOnParentImplicitly flag, is that right? As stated in this unit test: https://github.com/realvizu/NsDepCop/blob/83c34ce60855da2ada5e06ca91cf976731f59468/source/NsDepCop.Core.Test/Implementation/Analysis/TypeDependencyValidatorTests.cs#L133-L141