Skip to main content
WPILib uses modified Google style guides for both C++ and Java. All contributions must follow these style guidelines and be properly formatted.

Style Guides

WPILib’s style guides are maintained in the styleguide repository. Autoformatters are available for many popular editors at https://github.com/google/styleguide.
Running wpiformat is required for all contributions and is enforced by our continuous integration system.

Legacy Code

While the library should be fully formatted according to the styles, additional elements of the style guide were not followed when the library was initially created. All new code should follow the guidelines.
If you are looking for some easy ramp-up tasks, finding areas that don’t follow the style guide and fixing them is very welcome.

Formatting and Linting

wpiformat

wpiformat can be executed anywhere in the repository: Windows:
py -3 -m wpiformat
macOS/Linux:
python3 -m wpiformat
See the styleguide README for wpiformat setup instructions.

Java Code Quality Tools

The Java code quality tools Checkstyle, PMD, and Spotless can be run via:
./gradlew javaFormat
SpotBugs can be run via the following tasks:
  • spotbugsMain
  • spotbugsTest
  • spotbugsDev
These tools will all be run automatically by the build task. To disable this behavior, pass the -PskipJavaFormat flag.

Java Autoformatter Only

If you only want to run the Java autoformatter:
./gradlew spotlessApply

CI Formatting

Once a PR has been submitted, formatting can be run in CI by commenting /format on the PR. A new commit will be pushed with the formatting changes.
The /format action has been temporarily disabled. The individual formatting commands can be run locally as shown above. Alternately, the Lint and Format action for a PR will upload a patch file that can be downloaded and applied manually.

Pull Request Requirements

Format Before Submitting

Ensure your code is properly formatted before submitting a pull request:
1

Run wpiformat

Execute wpiformat to format C++ code:
python3 -m wpiformat
2

Run Java formatters

Execute Java formatting tools:
./gradlew javaFormat
3

Verify with build

Run the build task to ensure all quality checks pass:
./gradlew build
4

Commit formatting changes

If the formatters made changes, commit them:
git add .
git commit -m "Apply code formatting"

Continuous Integration Checks

When you submit a pull request, GitHub Actions will run ./gradlew check to verify:
  • Code formatting compliance
  • Code quality checks (Checkstyle, PMD, SpotBugs)
  • All tests pass
  • Build succeeds
If CI fails, you will need to fix any issues before the PR can be merged.

Language-Specific Guidelines

C++ Guidelines

WPILib uses a modified Google C++ Style Guide. Key points:
  • Use .cpp and .h file extensions
  • Follow naming conventions in the style guide
  • Use modern C++ features appropriately
  • Ensure code is wrappable in Python for RobotPy

Java Guidelines

WPILib uses a modified Google Java Style Guide. Key points:
  • Follow naming conventions in the style guide
  • Use appropriate Java language features
  • Maintain parity with C++ implementations where applicable

Generated Files

WPILib uses code generation for some files. If you modify templates or regenerate files:
  • Run the appropriate generation script
  • Commit the generated files
  • See Generated Files for more information

Documentation Standards

Code Comments

  • Use clear, concise comments
  • Document public APIs thoroughly
  • Explain complex algorithms or non-obvious code

API Documentation

  • Java: Use Javadoc comments
  • C++: Use Doxygen comments
  • Document parameters, return values, and exceptions

Best Practices

  • Write clean, readable code
  • Follow the principle of least surprise
  • Maintain consistency with existing code
  • Keep backwards compatibility in mind
  • Write self-documenting code when possible

Next Steps

Build docs developers (and LLMs) love