Skip to content

diffplug/spotless

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Spotless: Keep your code spotless

Gradle Plugin Maven Plugin SBT Plugin

Spotless can format <antlr | c | c# | c++ | css | flow | graphql | groovy | html | java | javascript | json | jsx | kotlin | less | license headers | markdown | objective-c | protobuf | python | scala | scss | shell | sql | typeScript | vue | yaml | anything> using <gradle | maven | sbt | anything>.

You probably want one of the links below:

user@machine repo % ./gradlew build
:spotlessJavaCheck FAILED
  The following files had format violations:
  src\main\java\com\diffplug\gradle\spotless\FormatExtension.java
    -\t\tΒ·Β·Β·Β·ifΒ·(targets.lengthΒ·==Β·0)Β·{
    +\t\tifΒ·(targets.lengthΒ·==Β·0)Β·{
  Run './gradlew spotlessApply' to fix these violations.
user@machine repo % ./gradlew spotlessApply
:spotlessApply
BUILD SUCCESSFUL
user@machine repo % ./gradlew build
BUILD SUCCESSFUL
user@machine repo % mvn spotless:check
[ERROR]  > The following files had format violations:
[ERROR]  src\main\java\com\diffplug\gradle\spotless\FormatExtension.java
[ERROR]    -\t\tΒ·Β·Β·Β·ifΒ·(targets.lengthΒ·==Β·0)Β·{
[ERROR]    +\t\tifΒ·(targets.lengthΒ·==Β·0)Β·{
[ERROR]  Run 'mvn spotless:apply' to fix these violations.
user@machine repo % mvn spotless:apply
[INFO] BUILD SUCCESS
user@machine repo % mvn spotless:check
[INFO] BUILD SUCCESS

How it works (for potential contributors)

Ideally, a code formatter can do more than just find formatting errors - it should fix them as well. Such a formatter is just a Function<String, String>, which returns a formatted version of its potentially unformatted input.

It's easy to build such a function, but there are some gotchas and lots of integration work (newlines, character encodings, idempotency, git ratcheting, and build-system integration). Spotless tackles those for you so you can focus on just a simple Function<String, String> which can compose with any of the other formatters and build tools in Spotless' arsenal.

Current feature matrix

Feature / FormatterStep gradle maven sbt (Your build tool here)
Automatic idempotency safeguard πŸ‘ πŸ‘ πŸ‘ ⬜
Misconfigured encoding safeguard πŸ‘ πŸ‘ πŸ‘ ⬜
Toggle with spotless:off and spotless:on πŸ‘ πŸ‘ ⬜ ⬜
Ratchet from origin/main or other git ref πŸ‘ πŸ‘ ⬜ ⬜
Define line endings using git πŸ‘ πŸ‘ πŸ‘ ⬜
Fast incremental format and up-to-date check πŸ‘ πŸ‘ ⬜ ⬜
Fast format on fresh checkout using buildcache πŸ‘ ⬜ ⬜ ⬜
generic.EndWithNewlineStep πŸ‘ πŸ‘ ⬜ ⬜
generic.IndentStep πŸ‘ πŸ‘ ⬜ ⬜
generic.Jsr223Step ⬜ πŸ‘ ⬜ ⬜
generic.LicenseHeaderStep πŸ‘ πŸ‘ πŸ‘ ⬜
generic.NativeCmdStep πŸ‘ πŸ‘ ⬜ ⬜
generic.ReplaceRegexStep πŸ‘ πŸ‘ ⬜ ⬜
generic.ReplaceStep πŸ‘ πŸ‘ ⬜ ⬜
generic.TrimTrailingWhitespaceStep πŸ‘ πŸ‘ ⬜ ⬜
antlr4.Antlr4FormatterStep πŸ‘ πŸ‘ ⬜ ⬜
biome.BiomeStep πŸ‘ πŸ‘ ⬜ ⬜
cpp.ClangFormatStep πŸ‘ ⬜ ⬜ ⬜
cpp.EclipseFormatterStep πŸ‘ πŸ‘ πŸ‘ ⬜
go.GofmtFormatStep πŸ‘ ⬜ ⬜ ⬜
gherkin.GherkinUtilsStep πŸ‘ πŸ‘ ⬜ ⬜
groovy.GrEclipseFormatterStep πŸ‘ πŸ‘ πŸ‘ ⬜
java.GoogleJavaFormatStep πŸ‘ πŸ‘ πŸ‘ ⬜
java.ImportOrderStep πŸ‘ πŸ‘ πŸ‘ ⬜
java.PalantirJavaFormatStep πŸ‘ πŸ‘ ⬜ ⬜
java.RemoveUnusedImportsStep πŸ‘ πŸ‘ πŸ‘ ⬜
java.EclipseJdtFormatterStep πŸ‘ πŸ‘ πŸ‘ ⬜
java.FormatAnnotationsStep πŸ‘ πŸ‘ ⬜ ⬜
java.CleanthatJavaStep πŸ‘ πŸ‘ ⬜ ⬜
json.gson.GsonStep πŸ‘ πŸ‘ ⬜ ⬜
json.JacksonJsonStep πŸ‘ πŸ‘ ⬜ ⬜
json.JsonSimpleStep πŸ‘ πŸ‘ ⬜ ⬜
json.JsonPatchStep πŸ‘ πŸ‘ ⬜ ⬜
kotlin.KtLintStep πŸ‘ πŸ‘ πŸ‘ ⬜
kotlin.KtfmtStep πŸ‘ πŸ‘ ⬜ ⬜
kotlin.DiktatStep πŸ‘ πŸ‘ ⬜ ⬜
markdown.FreshMarkStep πŸ‘ ⬜ ⬜ ⬜
markdown.FlexmarkStep πŸ‘ πŸ‘ ⬜ ⬜
npm.EslintFormatterStep πŸ‘ πŸ‘ ⬜ ⬜
npm.PrettierFormatterStep πŸ‘ πŸ‘ ⬜ ⬜
npm.TsFmtFormatterStep πŸ‘ πŸ‘ ⬜ ⬜
pom.SortPomStep πŸ‘ πŸ‘ ⬜ ⬜
protobuf.BufStep πŸ‘ ⬜ ⬜ ⬜
python.BlackStep πŸ‘ ⬜ ⬜ ⬜
rdf.RdfFormatterStep ⬜ πŸ‘ ⬜ ⬜
scala.ScalaFmtStep πŸ‘ πŸ‘ πŸ‘ ⬜
shell.ShfmtStep πŸ‘ πŸ‘ ⬜ ⬜
sql.DBeaverSQLFormatterStep πŸ‘ πŸ‘ πŸ‘ ⬜
wtp.EclipseWtpFormatterStep πŸ‘ πŸ‘ ⬜ ⬜
yaml.JacksonYamlStep πŸ‘ πŸ‘ ⬜ ⬜
(Your FormatterStep here) ⬜ ⬜ ⬜ ⬜

Why are there empty squares?

Many projects get harder to work on as they get bigger. Spotless is easier to work on than ever, and one of the reasons why is that we don't require contributors to "fill the matrix". If you want to add Bazel support, we'd happily accept the PR even if it only supports the one formatter you use. And if you want to add FooFormatter support, we'll happily accept the PR even if it only supports the one build system you use.

Once someone has filled in one square of the formatter/build system matrix, it's easy for interested parties to fill in any empty squares, since you'll now have a working example for every piece needed.

Acknowledgements