This project has moved. For the latest updates, please go here.
1

Closed

Class level dependencies?

description

It would be nice to whitelist specific classes from third-party libraries with monolithic namespaces.

The Unity game engine has every class in the UnityEngine namespace. In general I don't want the game logic layer to depend on Unity, but I'd like to make an exception for Vector and math classes.

Maybe a "ToClass" property?
<NsDepCopConfig>
    <Allowed From="GameLogic" ToClass="UnityEngine.Vector2" />
    <Allowed From="GameLogic" ToClass="UnityEngine.Vector3" />
    <!--
    Don't want the whole enchilada
    <Allowed From="GameLogic" To="UnityEngine" />
     -->
</NsDepCopConfig>
Here's how Checkstyle handles it for reference purposes:
<allow class="java.security.MessageDigest" local-only="true"/>
<allow class="java.security.NoSuchAlgorithmException" local-only="true"/>
<allow pkg="com.puppycrawl.tools.checkstyle.grammars" local-only="true"/>
<allow pkg="org.apache.commons.cli" local-only="true"/>
http://checkstyle.sourceforge.net/config_imports.html#ImportControl
https://github.com/checkstyle/checkstyle/blob/master/config/import-control.xml
Closed Jan 19 at 9:05 AM by vizu

comments

vizu wrote Feb 9, 2016 at 7:25 PM

I see your point.
I'll look into the implementation impact as soon as I'll have some time.

vizu wrote Jun 10, 2016 at 12:51 PM

New feature added in v1.5: you can define that only a part of a namespace is visible to other namespaces. Hope this resolves your scenario.

Use a config similar to this:
<NsDepCopConfig>
    <Allowed From="GameLogic" To="UnityEngine" />
    <VisibleMembers OfNamespace="UnityEngine">
        <Type Name="Vector2" />
        <Type Name="Vector3" />
    </VisibleMembers>
</NsDepCopConfig>

wrote Jan 19 at 9:05 AM