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

ImportControl: new strategyOnMismatch property to xml file structure #4274

Closed
timurt opened this Issue Apr 23, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@timurt
Collaborator

timurt commented Apr 23, 2017

Previous discussion #3451

Name of the property should be strategyOnMismatch with values allowed, disallowed, delegateToParent(should be default to keep compatibility) .

Rationale of your request is to "allow independent rules for subpackages". It will allow define completely isolated rules for special packages, for example:

  • to certainly keep control of api package;
  • control that domain packages are POJOs and use only jdk standard types/collections ;
  • or package that is extracted to separate artifact .

For import-control tag we should use same strategyOnMismatch property with one exception, it can not have value delegateToParent. We need to make it clear in documentation and throw exception is Check see delegateToParent defined on import-control (if possible that should be enforced by DTD).

Example:

<import-control pkg="com.puppycrawl.tools.checkstyle.checks" strategyOnMismatch="allowed">
  <allow class="java.awt.Image"/>
  <allow class="java.io.File" local-only="true"/>
  <subpackage name="imports" strategyOnMismatch="delegateToParent">
    <disallow class="java.awt.Image" local-only="true"/>
    <allow pkg="javax.swing" exact-match="true"/>
    <allow pkg="java.io" exact-match="true" local-only="true"/>
  </subpackage>
</import-control>

In this example we can see if we could not find suitable allow/disallow inside subpackage name="imports" then we go to the parent. If there is no suitable allow/disallow inside parent package, then import is allowed by default

@romani What do you think?

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Apr 23, 2017

Member

@timurt , issue is approved

Member

romani commented Apr 23, 2017

@timurt , issue is approved

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

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 12, 2017

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

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

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

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

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

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

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

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani May 28, 2017

Member

fix is merged

Member

romani commented May 28, 2017

fix is merged

@romani romani closed this May 28, 2017

@romani romani changed the title from ImportControl: strategyOnMismatch property to ImportControl: new strategyOnMismatch property to xml file structure May 28, 2017

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