Giter Club home page Giter Club logo

spotless's Introduction

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 | sql | typeScript | vue | yaml | anything> using <gradle | maven | sbt | anything>.

You probably want one of the links below:

❇️ Spotless for Gradle (with integrations for VS Code and 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
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 👍 👍
cpp.ClangFormatStep 👍
cpp.EclipseFormatterStep 👍 👍 👍
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.SortPomStepStep 👍
protobuf.BufStep 👍
python.BlackStep 👍
rome.RomeStep 👍 👍
scala.ScalaFmtStep 👍 👍 👍
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

spotless's People

Contributors

nedtwigg avatar simschla avatar fvgh avatar blacelle avatar lutovich avatar jbduncan avatar renovate[bot] avatar dependabot[bot] avatar mernst avatar abelk2 avatar source-knights avatar matthiasbalke avatar zacsweers avatar eirnym avatar blutorange avatar bigdaz avatar goooler avatar tisonkun avatar jlleitschuh avatar andrewparmet avatar tisoft avatar jamietanna avatar sineaggi avatar magneticflux- avatar star-zero avatar franvis avatar thc202 avatar bh-tt avatar davidgregory084 avatar smpanaro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.