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

IllegalImport: new property illegalClasses to let blacklist certain classes import #3449

Closed
romani opened this Issue Sep 19, 2016 · 8 comments

Comments

Projects
None yet
4 participants
@romani
Member

romani commented Sep 19, 2016

Base on discussion at #3358.

How about implementing a second parameter illegalClasses (default: null):

<module name="IllegalImport">
    <property name="illegalPkgs" value="sun, java.awt"/>
    <property name="illegalClasses" value="java.util.Date, java.util.Calendar"/>
</module>

Furthermore we could add a third parameter regexp (default: false) that determines whether the comma separated package or class names should be interpreted as regular expressions:

<module name="IllegalImport">
    <property name="illegalPkgs" value="sun, java\.awt"/>
    <property name="illegalClasses" value="java\.util\.(Calendar|Date)"/>
    <property name="regexp" value="true"/>
</module>

Both would support the mentioned case without interfering with the current behavior.

  1. Users might want to use more than one ImportControl check with varying severity. This would be much less straight forward using the ImportControlCheck, simply because it would require multiple import_control.xml files.
  2. Users might just want to globally forbid certain classes (such as old FindBugs annotations, where some annotations in the same package are still valid). In cases like this, defining an import_control.xml file seems like overkill to me, when the same could be achieved with just these two additional parameters.

@romani

This comment has been minimized.

Show comment
Hide comment
@romani
Member

romani commented Sep 20, 2016

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Oct 23, 2016

Member

one more request base on vanniktech's Tweet: https://twitter.com/vanniktech/status/788030816005873664?s=09

Member

romani commented Oct 23, 2016

one more request base on vanniktech's Tweet: https://twitter.com/vanniktech/status/788030816005873664?s=09

@rnveach rnveach added the medium label Mar 2, 2017

@timurt

This comment has been minimized.

Show comment
Hide comment
@timurt

timurt Mar 18, 2017

Collaborator

I am on it.

Collaborator

timurt commented Mar 18, 2017

I am on it.

@timurt

This comment has been minimized.

Show comment
Hide comment
@timurt

timurt Mar 18, 2017

Collaborator

whether the comma separated package or class names should be interpreted as regular expressions

What do you think about 2 separate regexp flags, one for packages one for classes?

Collaborator

timurt commented Mar 18, 2017

whether the comma separated package or class names should be interpreted as regular expressions

What do you think about 2 separate regexp flags, one for packages one for classes?

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Mar 18, 2017

Member

one should be enough, as you will just compare string in import with user defined string by regexp.
User is completely responsible for proper definition of RegExp.
It is user responsibility to make regexp like ^com.mycompany$, com.company.MyBadClass to make proper/strict match.
You will add that case in xdoc file as description of property and example to show user what is expected.

Member

romani commented Mar 18, 2017

one should be enough, as you will just compare string in import with user defined string by regexp.
User is completely responsible for proper definition of RegExp.
It is user responsibility to make regexp like ^com.mycompany$, com.company.MyBadClass to make proper/strict match.
You will add that case in xdoc file as description of property and example to show user what is expected.

@timurt

This comment has been minimized.

Show comment
Hide comment
@timurt

timurt Mar 20, 2017

Collaborator

I finished with java coding, now I am doing config_imports.xml. Should I edit <subsection name="Examples">, if yes how can I preview my editings.

Collaborator

timurt commented Mar 20, 2017

I finished with java coding, now I am doing config_imports.xml. Should I edit <subsection name="Examples">, if yes how can I preview my editings.

@Vladlis

This comment has been minimized.

Show comment
Hide comment
@Vladlis

Vladlis Mar 20, 2017

Member

@timurt
Yes, add new examples. You can generate site to validate changes, take a look at our wiki:
https://github.com/checkstyle/checkstyle/wiki/Build-all-jars-and-generate-maven-site

Member

Vladlis commented Mar 20, 2017

@timurt
Yes, add new examples. You can generate site to validate changes, take a look at our wiki:
https://github.com/checkstyle/checkstyle/wiki/Build-all-jars-and-generate-maven-site

timurt pushed a commit to timurt/checkstyle that referenced this issue Mar 20, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Mar 20, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Mar 25, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Mar 25, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Mar 29, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Apr 11, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Apr 15, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Apr 16, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Apr 16, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Apr 16, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Apr 16, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Apr 23, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Apr 24, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue Apr 27, 2017

timurt pushed a commit to timurt/checkstyle that referenced this issue May 1, 2017

romani added a commit that referenced this issue May 1, 2017

@romani romani added the new feature label May 1, 2017

@romani romani added this to the 7.8 milestone May 1, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani May 1, 2017

Member

fix is merged

Member

romani commented May 1, 2017

fix is merged

@romani romani closed this May 1, 2017

timurt added a commit to timurt/checkstyle that referenced this issue May 6, 2017

timurt added a commit to timurt/checkstyle that referenced this issue May 6, 2017

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