NsDepCop icon indicating copy to clipboard operation
NsDepCop copied to clipboard

Disallowing selected types of a namespace

Open realvizu opened this issue 1 year ago • 2 comments

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>

realvizu avatar Sep 07 '24 08:09 realvizu

@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>

shahabganji avatar Sep 29 '24 18:09 shahabganji

Corrected it, thanks!

realvizu avatar Sep 30 '24 05:09 realvizu