• Stars
    star
    3,791
  • Rank 11,072 (Top 0.3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Keep your code spotless

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

❇️ 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 (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 👍 👍
kotlin.KtLintStep 👍 👍 👍
kotlin.KtfmtStep 👍 👍
kotlin.DiktatStep 👍 👍
markdown.FreshMarkStep 👍
markdown.FlexmarkStep 👍
npm.EslintFormatterStep 👍 👍
npm.PrettierFormatterStep 👍 👍
npm.TsFmtFormatterStep 👍 👍
pom.SortPomStep 👍
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

More Repositories

1

durian

Guava's spikier (unofficial) cousin
Java
271
star
2

goomph

IDE as build artifact
Java
125
star
3

matfilerw

Read and write MATLAB MAT-files from Java, forked from JMatIO
Java
55
star
4

matconsolectl

Control MATLAB from Java, forked from matlabcontrol
Java
45
star
5

gradle-and-eclipse-rcp

Gradle and Eclipse RCP
Java
44
star
6

spotless-changelog

The changelog is cast, let the versions fall where they may.
Java
42
star
7

durian-swt

Reactive utilities and fluent builders for SWT
Java
29
star
8

selfie

Snapshot testing for Java, Kotlin, and the JVM
Kotlin
26
star
9

blowdryer

Keep your gradle builds dry 干
Java
23
star
10

osgiX

Expose the entire JRE to OSGi using extension bundles
22
star
11

freshmark

Keep your markdown fresh
Java
21
star
12

durian-rx

Reactive getters, powered by RxJava and ListenableFuture
Java
19
star
13

swt-chromium

Exploration repository for SWT-Chromium
Java
14
star
14

rxjava-and-swt

RxJava and SWT: Out with Events, in with FRP
Java
13
star
15

jscriptbox

Language-independent scripting environment
Java
8
star
16

JMatIO

Java Matlab IO library - actively maintained as MatFileRW
Java
7
star
17

atplug

AtPlug: Sockets and Plugs without the boilerplate
Kotlin
6
star
18

durian-globals

Globals are useful. Durian makes them testable too.
Java
4
star
19

durian-debug

Utilities for quick 'n dirty debugging and profiling
Java
4
star
20

image-grinder

ImageGrinder: Image manipulation for Gradle
Java
2
star
21

eclipse.platform.swt.binaries

Unofficial mirror the Eclipse SWT binaries repository
HTML
1
star
22

goomph-eclipse-plugin

Example project for using goomph to create an eclipse plugin
Java
1
star
23

gitfromscratch

A tutorial for learning git from scratch
CSS
1
star
24

libxdiff

LibXDiff ported to java
Java
1
star