This is a maven plugin to format code with checkstyle rules.
Currently the following rules are formatted automatically:
- Final Parameters
- Import Order
- Indentation
- File Tab Character
- Generic Whitespace
- NoWhitespaceBefore
- NoWhitespaceAfter
- WhitespaceAfter
- WhitespaceAround
The plugin is configured like the checkstyle plugin (from which it is derived).
See in their documentation for configuration options: Maven Checkstyle Plugin.
There is one more configuration option: You can configure, which new line character will be chosen when writing the files. You can do this with the checkstyleFormatter.lineEndingproperty.
When you report a bug, please come up with a pull-request that demonstrates the bug with a failing test:
-
Create a source tree in
src/it/javawith the code that is not formatted correctly and another source tree with the code with the expected formatting result. -
Create a test that references your source tree:
import org.junit.Rule;
import org.junit.Test;
import dev.limburg.checkstyle.CheckstyleFormatterRule;
public class YourTest {
@Rule
public CheckstyleFormatterRule rule = new CheckstyleFormatterRule();
@Test
public void formatFinalParameter() throws Exception {
rule.given("src/it/java/your/source/tree/with/the/failing/code");
rule.whenExecuteFormatting();
rule.thenResultIsSameAs("src/it/java/your/source/tree/with/the/expected/result");
}
}
The created test should fail. This demonstrates the bug.
We always implement formatters test-driven.
So when you want to contribute a formatter, please first create a failing test like described in "Reporting a bug".
Then implement your formatter by implementing the interface LineFormatter
and register it in the class FileFormatter with the corresponding key of the formatted checkstyle rule.