Formatting Rules
The code style conventions used in the project are based on the style-guide defined of Fedora-3. They should prevent commits cluttered with format changes.
Here are the major rules:
- Four space indents for Java, and 2-space indents for XML. NO TABS
K&R style braces
if (code) { // code } else { // code }- Do not use wildcard imports
- Write Javadocs for public methods and classes. Keep it short and to the point
- Avoid public instance variables; use accessors
- Use public methods sparingly; implementation details are not public
- Maximum length of lines is 120 characters.
Create Javadocs for types of at least the following descriptivity
/** * @author Joe Developer */ public class MyClass
Each source file should contain a license header much like the following (which can be automatically added by running
mvn license:format):/* * The contents of this file are subject to the license and copyright * detailed in the LICENSE and NOTICE files at the root of the source * tree. */
IDE Setups
IDE settings are located in the project source. IDE users are strongly recommended to apply these formatting settings.
- Eclipse settings are here: https://github.com/fcrepo/fcrepo/tree/main/src/site/eclipse
- IntelliJ settings TBD (purportedly, this plugin will let you use the Eclipse settings above within IntelliJ)
Checkstyle
We use checkstyle enforcement to our modules (meaning, if you violate some of the major style rules, the build will fail).
To check for violations, run the following command:
mvn checkstyle:check
2 Comments
Edwin Shin
There is some impedance mismatch between the Eclipse formatter rules and Checkstyle.
For example, per Feature Request #934551 (which has been open for over a year), Checkstyle doesn't allow for a "throws" declaration that has wrapped to a new line to be indented further than the method body:
public LegacyMethod(final Event jcrEvent, final Node resource) throws RepositoryException { this(EntryFactory.newEntry());But Eclipse (and the standard Java Code Conventions) prefer a further indenting:
public LegacyMethod(final Event jcrEvent, final Node resource) throws RepositoryException { this(EntryFactory.newEntry());The workaround in Eclipse is a hack if you have save actions defined (i.e. Eclipse will re-format your changed lines according to your settings, despite your efforts to manually adjust formatting to match the checkstyle requirements):
A. Soroka
Thanks, Edwin Shin. I was just about to write a message asking this very question.