Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
titleDSpace Java Style Guide is enforced on "main" branch

As of March June 2023, the below VIVO/Vitro Java Style Guide is will be enforced on all Pull Requests to the "main" branch for newly created files. Therefore, if a Pull Request to the "main" branch does not align with the below Style Guide, it will fail the build process within our GitHub CI.

  1. 4-space indents. NO TABS ALLOWED.
  2. One true brace style. Braces are required on all blocks.

    Code Block
    if (code) {
      // code
    } else {
      // code
    }


  3. Do not use wildcard imports (e.g. import java.util.*). Duplicated or unused imports are not allowed.
  4. Maximum length of lines is 100 characters (except for long URLs, packages or imports)

  5. No trailing spaces allowed (except in comments)
  6. Tokens should be surrounded by whitespace, e.g. http://checkstyle.sourceforge.net/config_whitespace.html#WhitespaceAround

    Code Block
    // This is NOT valid. Whitespace around tokens is missing
    String []={"one","two","three"}
    
    // This is valid. Whitespace exists around all tokens
    String [] = { "one", "two", "three" }


  7. Each line of code can only include one statement.  This also means each variable declaration must be on its own line, e.g.

    Code Block
    // This is NOT valid. Three variables are declared on one line
    String first = "", second = "", third = "";
    
    // This is valid. Each statement is on its own line
    String first = "";
    String second = "";
    String third = "";


  8. Each source file must contain the required VIVO/Vitro license header, e.g.

    Code Block
    /*
     * This file is distributed under the terms of the license in the LICENSE file in the root of this project
     */


Resources

IDE Support

Most major IDEs include plugins that support Checkstyle configurations. The plugin usually let you import an existing "checkstyle.xml" configuration to configure your IDE to use and/or validate against that style.

...