sming
sming

Reputation: 811

Java checkstyle import statement indentation

I'm trying to prevent inconsistent indentations in import statements like this:

...
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
    import org.junit.Before;            // ← this line
import org.junit.Test;
import org.junit.runner.RunWith;
...

The Indentation module doesn't do the trick, nor does the import config

What am I missing? Thanks.

Upvotes: 1

Views: 111

Answers (1)

VGR
VGR

Reputation: 44404

I’m pretty sure the Indentation rule is only meant for content of blocks (if, for, while, switch, etc.).

Use RegexpSinglelineJava instead:

<module name="RegexpSinglelineJava">
    <property name="format" value="^\s+import\b"/>
    <property name="message" value="import statements must start in the first column."/>
    <property name="ignoreComments" value="true"/>
</module>

Upvotes: 1

Related Questions