Skip to content

ImportOrder: option=under; doesn't allow empty line between 'import' and 'import static' #5460

@mar-kolya

Description

@mar-kolya

Test file:

$ cat ./Test.java 
package test.test;

import java.some.common.collect1.Lists1;

import static java.some.common.collect1.Lists1.asList;

import com.google.common.collect.Lists;

import static com.google.common.collect.Lists.asList;

public class Test {
    public void test() {
        Lists.cartesianProduct(null, null);
        asList(null, null);
    }
}

Config:

$ 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">
    <module name="TreeWalker">
    <module name="ImportOrder">
      <property name="groups" value="/^java\./,javax,org,com,net,edu,io"/>
      <property name="ordered" value="true"/>
      <property name="separated" value="true"/>
      <property name="option" value="under"/>
      <property name="useContainerOrderingForStatic" value="true"/>
    </module>

    </module>
</module>

java -Duser.language=en -Duser.country=US -jar ~/Downloads/checkstyle-8.7-all.jar -c config.xml Test.java:

Starting audit...
[ERROR] /var/tmp/Test.java:5: Extra separation in import group before
 'java.some.common.collect1.Lists1.asList' [ImportOrder]
[ERROR] /var/tmp/Test.java:9: Extra separation in import group before
 'com.google.common.collect.Lists.asList' [ImportOrder]
Audit done.
Checkstyle ends with 2 errors.

Eclipse Mars inserts empty lines between non static and static imports. This used to work with checkstyle 7.4. With latest checkstyle I could not make a config that would work.

Above file is saved with Eclipse's import order like this:

$ cat ./style.importorder 
9=\#net
8=net
7=\#com
6=com
5=\#org
13=\#io
4=org
12=io
3=\#javax
11=\#edu
2=javax
10=edu
1=\#java
0=java

Please let me know if more information is needed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions