1

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.

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Nice! Thanks. It's surprising that import statements are not covered out of the box, to me at least.
So. It turns out that the Indentation module does not cover import statements in 6.19. However it does cover import statements in 8.37. So to summarize: use @VGR's solution above for 6.19 (6.x too?) and the Indentation module for 8.37 (8.x too ?). Cheers @VGR!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.