Spotless: Keep your code spotless 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: βοΈ Spotless for Gradle (with integrations for IntelliJ) 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 βοΈ Spotless for Maven 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 βοΈ Spotless for SBT (external for now) Other build systems 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 (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.ForbidWildcardImportsStep π β¬ java.ForbidModuleImportsStep π β¬ 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 Thanks to over 200 contributors with merged PRs, and also to everyone who helped with code review, file reproducible bugs, etc. A few contributions stand out as especially significant to the history of the project, though regrettably there are certain to be some important omissions! Thanks to his near-rewrite so that Spotless could support Gradle's configuration cache natively. Thanks to twice including prettier and tsfmt. Thanks to remote-build cache support for Gradle. Thanks to XML support via WTP and a huge body of work with other eclipse-based formatters. Thanks to Jonathan Bluett-Duncan for implementing up-to-date checking #31 breaking spotless into libraries #56 lots of other things, but especially the diff support in spotlessCheck constant improvements on a variety of topics with high-quality code reviews Thanks to lazy configuration. Thanks to VS Code extension for Spotless Gradle. Thanks to IntelliJ plugin for Spotless Gradle. Thanks to git pre-push hook. Thanks to maven pom sorting. Thanks to adding support for Antlr. Thanks to #563) Thanks to skip-reflowing-long-strings option. Thanks to wildcards last support to the import sorter. Thanks to fixing Groovy for multiproject. Thanks to sql formatting support for JDBI bind list params. Thanks to custom mavenCoordinate support to google-java-format. Thanks to fixing a file-permissions-clobbering bug. Thanks to fixing scalafmt integration. Thanks to fixing scalafmt post-2.0. Thanks to Baptiste Mesta for porting the DBeaver formatter to Spotless, and thanks to DBeaver and its authors for their excellent SQL formatter. making license headers date-aware #179 Thanks to #392), respectively. Thanks to #426). Thanks to Stefan Oehme for tons of help on the internal mechanics of Gradle. Thanks to eyalkaspi for adding configurable date ranges to the date-aware license headers. Thanks to ktfmt support for kotlin gradle. Thanks to Oliver Horn for adding AOSP support for Spotless' google-java-format integration. Formatting by Eclipse Special thanks to Mateusz Matela for huge improvements to the eclipse code formatter! Thanks to #434 and others). Thanks to #974). Thanks to Nelson Osacky for android doc improvements, versions bump, and a build improvement. Thanks to ktlint. Thanks to Gradle Kotlin DSL files. Originally forked from gradle-format-plugin by Youri BonnaffΓ©. Thanks to IsmaΓ«l MejΓa for bumping eclipse-jdt deps to 4.11. PR #60. Thanks to GΓ‘bor BernΓ‘t for improvements to logging and multi-project support. Thanks to prettier to maven. Thanks to Andrew Oberstar for improvements to formatting java source in non-java source sets. PR #60. Thanks to adding support for IntelliJ-style year placeholders. Thanks to adding a simple JSON formatter. Thanks to #506. Import ordering from EclipseCodeFormatter. Built by gradle. Tested by junit. Maintained by DiffPlug.