Spotless is a tool that automatically formats code to follow a certain convention. It allows multiple developers to write code but still maintain some uniformity in bracketing, indentation, whitespace, etc of the code.
This implementation of spotless mainly enforces the Google Java Style, replaced tab indentation with spaces, and trims any trailing whitespace in files.
Summary of changes:
build.gradle
- Install the spotless plug-in
- Configure the spotless settings for the various file types (java, gradle, xml, etc)
- Disable automatics spotless execution during a build
- By default, spotless is configured to run during a build. This is generally undesirable because we don't want formatting errors to cause build failures and hinder developent, debugging, and testing. We generally want to run and apply the spotless changes prior to committing and/or pushing the code to a source code repository (e.g. git)
Once spotless is configured, you can run and apply the spotless changes by running spotlessApply
via Gradle.
From vscode, you can run spotless as follows:
- Open the vscode command palette:
Ctrl-Shift-P
- Type/Select:
WPILib: Run a command in Gradle
- Type:
spotlessApply
Summary of changes:
- Code reformatted by spotless
To keep the code base as uniform as possible, all subsequent changes should be processed by spotless prior to pushing it to the shared repository.