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

ImportOrder with option=bottom should not allow non-static import after static import #4981

Closed
julianhyde opened this Issue Aug 22, 2017 · 7 comments

Comments

Projects
None yet
3 participants
@julianhyde
Contributor

julianhyde commented Aug 22, 2017

http://checkstyle.sourceforge.net/config_imports.html#ImportOrder
http://checkstyle.sourceforge.net/property_types.html#importOrder

/var/tmp $ javac InputImportOrderStaticGroupOrderBottom_Negative.java

(no output)

/var/tmp $ cat -n InputImportOrderStaticGroupOrderBottom_Negative.java

  1 package com.puppycrawl.tools.checkstyle.checks.imports.importorder;
  2
  3 import org.*;
  4
  5 import static java.lang.Math.PI;
  6 import static org.antlr.v4.runtime.Recognizer.EOF;
  7
  8 import java.util.Set;
  9
 10 public class InputImportOrderStaticGroupOrderBottom_Negative
 11 {
 12
 13 }

/var/tmp $ cat config.xml

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
  <property name="charset" value="UTF-8"/>

  <module name="TreeWalker">
    <module name="ImportOrder">
      <property name="groups" value="org,java"/>
      <property name="option" value="bottom"/>
      <property name="sortStaticImportsAlphabetically" value="true"/>
    </module>
  </module>
</module>

/var/tmp $ java -jar checkstyle-X.XX-all.jar -c config.xml InputImportOrderStaticGroupOrderBottom_Negative.java

Gives no errors, but I would expect

InputImportOrderStaticGroupOrderBottom_Negative.java:8: Wrong order for 'java.util.Set' import.
@julianhyde

This comment has been minimized.

Show comment
Hide comment
@julianhyde
Contributor

julianhyde commented Aug 22, 2017

@julianhyde

This comment has been minimized.

Show comment
Hide comment
@julianhyde

julianhyde Sep 12, 2017

Contributor

@romani Please review and approve.

Contributor

julianhyde commented Sep 12, 2017

@romani Please review and approve.

@romani romani changed the title from ImportOrder with order=bottom should not allow non-static import after static import to ImportOrder with option=bottom should not allow non-static import after static import Sep 13, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Sep 13, 2017

Member

@julianhyde , sorry for delay, thank for bringing it back to attention.
Issue is approved, please proceed with PR

Member

romani commented Sep 13, 2017

@julianhyde , sorry for delay, thank for bringing it back to attention.
Issue is approved, please proceed with PR

@julianhyde

This comment has been minimized.

Show comment
Hide comment
@julianhyde

julianhyde Sep 20, 2017

Contributor

See PR #5130

Contributor

julianhyde commented Sep 20, 2017

See PR #5130

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Sep 20, 2017

Member

@julianhyde

InputImportOrderStaticGroupOrderBottom_Negative.java
Gives no errors

I get an error which regresses all the way back to version 7, but it is not the violation you are asking for.

$ cat TestClass.java
package com.puppycrawl.tools.checkstyle.checks.imports.importorder;

import org.*;

import static java.lang.Math.PI;
import static org.antlr.v4.runtime.Recognizer.EOF;

import java.util.Set;

public class InputImportOrderStaticGroupOrderBottom_Negative {
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
    <module name="ImportOrder">
      <property name="groups" value="org,java"/>
      <property name="ordered" value="true"/>
      <property name="separated" value="true"/>
      <property name="option" value="bottom"/>
    </module>
    </module>
</module>

$ java -jar checkstyle-8.2-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:6: Wrong order for 'org.antlr.v4.runtime.Recognizer.EOF' import. [ImportOrder]
Audit done.
Checkstyle ends with 1 errors.

When I fix up this error I get the error you are looking for:

$ cat TestClass.java
package com.puppycrawl.tools.checkstyle.checks.imports.importorder;

import org.*;

import static org.antlr.v4.runtime.Recognizer.EOF;

import static java.lang.Math.PI;

import java.util.Set;

public class InputImportOrderStaticGroupOrderBottom_Negative {
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
    <module name="ImportOrder">
      <property name="groups" value="org,java"/>
      <property name="ordered" value="true"/>
      <property name="separated" value="true"/>
      <property name="option" value="bottom"/>
    </module>
    </module>
</module>

$ java -jar checkstyle-8.2-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:9: Wrong order for 'java.util.Set' import. [ImportOrder]
Audit done.
Checkstyle ends with 1 errors.

Am I missing something? Can you fix up your issue so it is repeatable?

Member

rnveach commented Sep 20, 2017

@julianhyde

InputImportOrderStaticGroupOrderBottom_Negative.java
Gives no errors

I get an error which regresses all the way back to version 7, but it is not the violation you are asking for.

$ cat TestClass.java
package com.puppycrawl.tools.checkstyle.checks.imports.importorder;

import org.*;

import static java.lang.Math.PI;
import static org.antlr.v4.runtime.Recognizer.EOF;

import java.util.Set;

public class InputImportOrderStaticGroupOrderBottom_Negative {
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
    <module name="ImportOrder">
      <property name="groups" value="org,java"/>
      <property name="ordered" value="true"/>
      <property name="separated" value="true"/>
      <property name="option" value="bottom"/>
    </module>
    </module>
</module>

$ java -jar checkstyle-8.2-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:6: Wrong order for 'org.antlr.v4.runtime.Recognizer.EOF' import. [ImportOrder]
Audit done.
Checkstyle ends with 1 errors.

When I fix up this error I get the error you are looking for:

$ cat TestClass.java
package com.puppycrawl.tools.checkstyle.checks.imports.importorder;

import org.*;

import static org.antlr.v4.runtime.Recognizer.EOF;

import static java.lang.Math.PI;

import java.util.Set;

public class InputImportOrderStaticGroupOrderBottom_Negative {
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
    <module name="ImportOrder">
      <property name="groups" value="org,java"/>
      <property name="ordered" value="true"/>
      <property name="separated" value="true"/>
      <property name="option" value="bottom"/>
    </module>
    </module>
</module>

$ java -jar checkstyle-8.2-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:9: Wrong order for 'java.util.Set' import. [ImportOrder]
Audit done.
Checkstyle ends with 1 errors.

Am I missing something? Can you fix up your issue so it is repeatable?

@julianhyde

This comment has been minimized.

Show comment
Hide comment
@julianhyde

julianhyde Sep 20, 2017

Contributor

My mistake. I have changed the contents of config.xml at the top of this case. Now checkstyle gives 0 errors without the fix, 1 error with the fix, as desired.

Contributor

julianhyde commented Sep 20, 2017

My mistake. I have changed the contents of config.xml at the top of this case. Now checkstyle gives 0 errors without the fix, 1 error with the fix, as desired.

julianhyde added a commit to julianhyde/checkstyle that referenced this issue Sep 21, 2017

djydewang added a commit to djydewang/checkstyle that referenced this issue Dec 10, 2017

djydewang added a commit to djydewang/checkstyle that referenced this issue Dec 12, 2017

djydewang added a commit to djydewang/checkstyle that referenced this issue Dec 12, 2017

romani added a commit that referenced this issue Dec 25, 2017

@romani romani added this to the 8.6 milestone Dec 25, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Dec 25, 2017

Member

fix is merged.
Thanks a lot to all participants.

Member

romani commented Dec 25, 2017

fix is merged.
Thanks a lot to all participants.

@romani romani closed this Dec 25, 2017

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