A VS Code extension to lint & format your code using Spotless (via Gradle).
- Provides diagnostics to show invalid formatting (with quick fixes)
- Provides a Spotless fixAll code action (
Format on Save
) - Provides a Spotless formatter (
Format Document
) - Supports all languages that Spotless supports
Before using this extension, ensure you've configured Spotless correctly in your Gradle build file. (Run ./gradlew spotlessDiagnose
to prepare & validate Spotless.)
Spotless formatting & diagnostics are disabled by default. Change the settings to adjust this behavior:
{
"[java]": {
"spotlessGradle.format.enable": true,
"spotlessGradle.diagnostics.enable": true
}
}
Format on save:
{
"[java]": {
"spotlessGradle.format.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.spotlessGradle": true
}
}
}
If there are multiple formatters for a language type, set Spotless to be the default:
{
"[java]": {
"spotlessGradle.format.enable": true,
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle"
}
}
Disable other formatters to improve the performance, for example:
{
"[java]": {
"spotlessGradle.format.enable": true,
"files.trimTrailingWhitespace": false
}
}
As Spotless formatting is not a global feature, you should enable Spotless on a per-project basis, which is achieved by adding a .vscode/settings.json
file to the root of the project
Enable for specific languages:
{
"java.format.enabled": false,
"[java]": {
"files.trimTrailingWhitespace": false,
"spotlessGradle.diagnostics.enable": true,
"spotlessGradle.format.enable": true,
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle",
"editor.codeActionsOnSave": {
"source.fixAll.spotlessGradle": true
}
},
"[gradle]": {
"files.trimTrailingWhitespace": false,
"spotlessGradle.diagnostics.enable": true,
"spotlessGradle.format.enable": true,
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle",
"editor.codeActionsOnSave": {
"source.fixAll.spotlessGradle": true
}
}
}
Enable for all languages:
{
"java.format.enabled": false,
"files.trimTrailingWhitespace": false,
"spotlessGradle.diagnostics.enable": true,
"spotlessGradle.format.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.spotlessGradle": true
},
"[java]": {
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle"
},
"[gradle]": {
"editor.defaultFormatter": "richardwillis.vscode-spotless-gradle"
}
}
This extension runs the spotlessApply
Gradle task on the focused file using the Spotless IDE hook feature. Untitled/Unsaved files are ignored.
The vscode => Spotless interface is provided by the Gradle for Java extension.
View logs by selecting Spotless Gradle
and/or Gradle for Java
in the output panel.
- 👉 Submit a bug report
- 👉 Submit a feature request
- Thanks to Ned Twigg for adapting Spotless for better IDE integration
- Thanks to all the Spotless contributors
See CHANGELOG.md.
See LICENSE.md.