Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions website/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,55 @@ foo(
```

Prettier Java enforces a consistent code **style** (i.e. code formatting that won't affect the AST) across your entire codebase because it disregards the original styling by parsing it away and re-printing the parsed AST with its own rules that take the maximum line length into account, wrapping code when necessary.

## Lambdas are supported well

Prettier Java is handling lambdas properly.
When formatting the example by [palantir-java-format](https://github.com/palantir/palantir-java-format#motivation--examples), one get this result:

```java
private static void configureResolvedVersionsWithVersionMapping(
Project project
) {
project
.getPluginManager()
.withPlugin("maven-publish", (plugin) -> {
project
.getExtensions()
.getByType(PublishingExtension.class)
.getPublications()
.withType(MavenPublication.class)
.configureEach((publication) ->
publication.versionMapping((mapping) -> {
mapping.allVariants(
VariantVersionMappingStrategy::fromResolutionResult
);
})
);
});
}
```

## Optmized for reading

The aim is to keep the code within 80 characters.
There might be "mart" exeptions, but as [Prettier states](https://prettier.io/docs/options#print-width), 80 characters are recommended for readability.

The [chained example by Palantir](https://github.com/palantir/palantir-java-format#optimised-for-code-review) is reformatted as follows:

```java
var foo = SomeType.builder()
.thing1(thing1)
.thing2(thing2)
.thing3(thing3)
.build();
```

## Configurable

Although, Prettier Java is opinionated, there are tweaks.

The most used seetings `.prettierrc.yaml` are

- `tabWidth: 4` to have an indent of `4` (instead of `2`) and
- `experimentalOperatorPosition: start` to have operators at the beginning of a code line (and not at the end).