Skip to content

Commit 2238d92

Browse files
committed
Add source formatting validation
1 parent 53569b1 commit 2238d92

3 files changed

Lines changed: 383 additions & 2 deletions

File tree

CONTRIBUTING.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,35 @@ in-depth knowledge of the codebase.
2424

2525
## Editor configuration
2626

27-
We use IntelliJ IDEA with the default formatting options, with one exception: check
28-
"Enable formatter markers in comments" in Preferences > Editor > Code Style.
27+
We use Eclipse formatting conventions with a few exceptions:
28+
29+
* Spaces instead of Tabs with 4 space indentation
30+
* No joining of wrapped lines (for leniency)
31+
* Disable auto-line wrapping (for leniency)
32+
* Disable formatting of comments (for leniency)
33+
* No spaces inserted before and after braces in array initializer
34+
* Indent statements within switch body
35+
* Add new lines after each enum constant
36+
37+
A formatting configuration is provided in [src/formatter/java.xml](src/formatter/java.xml)
38+
that can be importted into both Eclipse and IntelliJ.
39+
40+
Additionally, you may opt to use the formatting-maven-plugin to do the formatting for you
41+
by executing:
42+
43+
```
44+
mvn formatter:format
45+
```
46+
47+
In the module that you wish to do formatting for. This is required because the formatting
48+
plugin doesn''t currently recurse child modules.
49+
50+
Source format validation is done as part of the maven build and may be validated
51+
individually by executing:
52+
53+
```
54+
mvn formatter:validate
55+
```
2956

3057
Please format your code and organize imports before submitting your changes.
3158

pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,31 @@
338338
</execution>
339339
</executions>
340340
</plugin>
341+
<!--
342+
To update source formatting run:
343+
mvn formatter:format
344+
-->
345+
<plugin>
346+
<groupId>com.marvinformatics.formatter</groupId>
347+
<artifactId>formatter-maven-plugin</artifactId>
348+
<version>1.4.0</version>
349+
<configuration>
350+
<configFile>${main.basedir}/src/formatter/java.xml</configFile>
351+
<configJsFile>${main.basedir}/src/formatter/java.xml</configJsFile>
352+
<lineEnding>LF</lineEnding> <!-- linux style line endings -->
353+
<compilerCompliance>${java.version}</compilerCompliance>
354+
<compilerTargetPlatform>${java.version}</compilerTargetPlatform>
355+
</configuration>
356+
<executions>
357+
<execution>
358+
<id>check-format</id>
359+
<phase>initialize</phase>
360+
<goals>
361+
<goal>validate</goal>
362+
</goals>
363+
</execution>
364+
</executions>
365+
</plugin>
341366
<plugin>
342367
<groupId>org.codehaus.mojo</groupId>
343368
<artifactId>animal-sniffer-maven-plugin</artifactId>

0 commit comments

Comments
 (0)