Skip to content
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

Disallowing selected types of a namespace #75

Open
realvizu opened this issue Sep 7, 2024 Discussed in #74 · 2 comments
Open

Disallowing selected types of a namespace #75

realvizu opened this issue Sep 7, 2024 Discussed in #74 · 2 comments

Comments

@realvizu
Copy link
Owner

realvizu commented Sep 7, 2024

Make it possible to disallow selected types of a namespace.

Example use case: to prevent developers using the Assert type of Xunit and use FluentAssertions instead.

I can think of two different ways to specify this in the config: the first aligns better with an allowlisting approach, while the second fits more with a denylisting approach.

Allowlist approach:

<NsDepCopConfig IsEnabled="true" ChildCanDependOnParentImplicitly="true">

    <Allowed From="*" To="FluentAssertions">
    <Allowed From="*" To="Xunit">
        <DisallowedMembers>
            <Type Name="Assert" />
        </DisallowedMembers>
    </Allowed>

</NsDepCopConfig>

Denylist approach:

<NsDepCopConfig IsEnabled="true" ChildCanDependOnParentImplicitly="true">

    <Allowed From="*" To="*" />

    <DisallowedMembers OfNamespace="Xunit">
        <Type Name="Assert" />
    </DisallowedMembers>

</NsDepCopConfig>
@shahabganji
Copy link

shahabganji commented Sep 29, 2024

@realvizu In the above-mentioned code, the closing tag for DisallowedMembers is wrong!

<NsDepCopConfig IsEnabled="true" ChildCanDependOnParentImplicitly="true">

    <Allowed From="*" To="*" />

    <DisallowedMembers OfNamespace="Xunit">
        <Type Name="Assert" />
    </DisallowedMembers>

</NsDepCopConfig>

@realvizu
Copy link
Owner Author

Corrected it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants