Closed kirides closed 1 year ago
Thanks for the proposal, this would be a helpful enhancement indeed.
If anyone wants to contribute, I'm happy to help you figure out how to implement and unit test it.
I'd be happy to take a look at this one! I was just replying to someone and mentioned nsdepcop, and spotted this issue. I'd be happy to contribute to such a great utility!
Great! Thanks for volunteering!
Here are some thoughts that may help you get started.
Regarding unit testing:
It's the TypeDependencyValidatorTests class that contains the test cases for IsAllowedDependency.
Consider the following methods that test the effect of the 2 kinds of VisibleMembers (when the VisibleMembers is inside an Allowed rule, or when it's a global VisibleMembers definition):
So either these methods should check whether the AllowedTypeNames info is returned correctly, or some new test methods should be created for this purpose.
Also, there are end-to-end tests in the NsDepCop.SourceTest project. Specifically these test cases deal with VisibleMembers:
These end-to-end tests use the SourceTestSpecification class to build up a test case, execute it, and perform the necessary asserts.
The AssertIllegalDependencies method currently checks only whether the reported TypeDependency object's SourceSegment looks as expected. It should also check whether the expected AllowedTypeNames were also returned (if specified).
Probably the ExpectInvalidSegment builder method should accept an optional extra parameter (AllowedTypeNames), so it can be checked in AssertIllegalDependencies.
Which means that SourceTestSpecification.GetIllegalDependencies should also be refactored to either return the whole IllegalDependencyMessage, or both the TypeDependency and the AllowedTypeNames.
Hope I didn't overlook any serious roadblocks. Anyway, if you run into problems, then don't hesitate to reach out!
Here's a quick overview of the types involved:
Many thank for the detailed information! I'll hopefully have some time this week. Thanks again!
The new version is live on NuGet: https://www.nuget.org/packages/NsDepCop/2.3.0 Thanks for the proposal and the implementation!
Currently if we only allow users a subset of Types in a namespace, the user won't know which types are allowed unless they read through configs and documentation.
i propose that the emitted error in such cases
becomes more like this:
This would improve consuming such warnings/errors much easier