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.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:Java Code Quality Tools
The Java code quality tools Checkstyle, PMD, and Spotless can be run via:spotbugsMainspotbugsTestspotbugsDev
build task. To disable this behavior, pass the -PskipJavaFormat flag.
Java Autoformatter Only
If you only want to run the Java autoformatter: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: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
Language-Specific Guidelines
C++ Guidelines
WPILib uses a modified Google C++ Style Guide. Key points:- Use
.cppand.hfile 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