/spotless

Keep your code spotless

Primary LanguageJavaApache License 2.0Apache-2.0

Spotless: Keep your code spotless

Travis CI Live chat License Apache

Spotless can format <java | kotlin | scala | sql | groovy | javascript | flow | typeScript | css | scss | less | jsx | vue | graphql | json | yaml | markdown | license headers | anything> using <gradle | maven | anything>.

Ideally, a code formatter can do more than just find formatting errors - it should fix them as well. Such a formatter is really 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, 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 plugin-gradle plugin-maven (Your build tool here)
Automatic idempotency safeguard πŸ‘ πŸ‘ ⬜
Misconfigured encoding safeguard πŸ‘ πŸ‘ ⬜
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.LicenseHeaderStep πŸ‘ πŸ‘ ⬜
generic.ReplaceRegexStep πŸ‘ πŸ‘ ⬜
generic.ReplaceStep πŸ‘ πŸ‘ ⬜
generic.TrimTrailingWhitespaceStep πŸ‘ πŸ‘ ⬜
antlr4.Antlr4FormatterStep πŸ‘ πŸ‘ ⬜
cpp.EclipseFormatterStep πŸ‘ πŸ‘ ⬜
groovy.GrEclipseFormatterStep πŸ‘ ⬜ ⬜
java.GoogleJavaFormatStep πŸ‘ πŸ‘ ⬜
java.ImportOrderStep πŸ‘ πŸ‘ ⬜
java.RemoveUnusedImportsStep πŸ‘ πŸ‘ ⬜
java.EclipseJdtFormatterStep πŸ‘ πŸ‘ ⬜
kotlin.KtLintStep πŸ‘ πŸ‘ ⬜
kotlin.KtfmtStep πŸ‘ πŸ‘ ⬜
markdown.FreshMarkStep πŸ‘ ⬜ ⬜
npm.PrettierFormatterStep πŸ‘ πŸ‘ ⬜
npm.TsFmtFormatterStep πŸ‘ πŸ‘ ⬜
scala.ScalaFmtStep πŸ‘ πŸ‘ ⬜
sql.DBeaverSQLFormatterStep πŸ‘ ⬜ ⬜
wtp.EclipseWtpFormatterStep πŸ‘ πŸ‘ ⬜
(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