Skip to content

Latest commit

 

History

History
85 lines (63 loc) · 2.26 KB

File metadata and controls

85 lines (63 loc) · 2.26 KB

Code Formatting Guide

This project uses Google Java Format via the Spotless Maven Plugin for consistent code formatting.

Maven Commands

Check if code is properly formatted

mvn spotless:check

Automatically format all code

mvn spotless:apply

Format code as part of the build

The formatting check is automatically run during the compile phase, so:

mvn compile

will fail if code is not properly formatted.

IDE Configuration

IntelliJ IDEA

  1. Install the "google-java-format" plugin
  2. Go to FileSettingsOther Settingsgoogle-java-format Settings
  3. Enable "Enable google-java-format"

VS Code

  1. Install "Google Java Format for VS Code" extension

Eclipse

  1. Download eclipse-java-google-style.xml
  2. Import via WindowPreferencesJavaCode StyleFormatterImport

Import Order

The project uses a custom import order that differs from the standard Google Java Format ordering:

  1. Project imports: io.cassandrareaper.*
  2. Third-party libraries: All other external dependencies
  3. Java standard library: java.*
  4. Java extensions: javax.*
  5. Static imports: All static imports (at the end)

Example:

import io.cassandrareaper.AppContext;
import io.cassandrareaper.core.Cluster;

import com.google.common.collect.ImmutableSet;
import org.apache.commons.lang3.StringUtils;

import java.net.URI;
import java.util.Optional;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

import static com.google.common.base.Preconditions.checkArgument;

This ordering is automatically applied when running mvn spotless:apply.

Pre-commit Hook (Optional)

To automatically format code before commits, you can add this to your git pre-commit hook:

#!/bin/sh
mvn spotless:apply -q
git add .

Formatting Rules

The configuration includes:

  • Google Java Format style
  • Custom import order (project → third-party → java → javax → static)
  • Remove unused imports
  • Trim trailing whitespace
  • End files with newline
  • 2-space indentation
  • 100-character line limit