Skip to content

Commit b831695

Browse files
committed
Polish README
1 parent ec2f6fe commit b831695

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

README.adoc

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
:checkstyle-version: 8.32
33
== Spring Java Format
44

5-
=== What is this?
5+
6+
7+
=== What is This?
68
A set of plugins that can be applied to any Java project to provide a consistent "`Spring`" style.
79
The set currently consists of:
810

@@ -13,10 +15,13 @@ Since the aim of this project is to provide consistency, each plugin is not gene
1315
You need to change your code to match the required conventions.
1416
You can't configure the plugin conventions to match your style!
1517

18+
19+
1620
=== Maven
1721

18-
==== Source Formatting
1922

23+
24+
==== Source Formatting
2025
For source formatting, add the `spring-javaformat-maven-plugin` to your `build` plugins as follows:
2126

2227
[source,xml,indent=0,subs="normal"]
@@ -71,8 +76,9 @@ NOTE: The source formatter does not fundamentally change your code.
7176
For example, it will not change the order of import statements.
7277
It is effectively limited to adding or removing whitespace and line feeds.
7378

74-
=== Checkstyle
7579

80+
81+
=== Checkstyle
7682
To enforce checksyle conventions add the checkstyle plugin and include a dependency on `spring-javaformat-checkstyle`:
7783

7884
[source,xml,indent=0,subs="normal"]
@@ -114,8 +120,12 @@ To enforce checksyle conventions add the checkstyle plugin and include a depende
114120
</build>
115121
----
116122

123+
124+
117125
=== Gradle
118126

127+
128+
119129
==== Source Formatting
120130
For source formatting, add the `spring-javaformat-gradle-plugin` to your `build` plugins as follows:
121131

@@ -145,6 +155,8 @@ tasks.withType(io.spring.javaformat.gradle.CheckTask) {
145155
}
146156
----
147157

158+
159+
148160
==== Checkstyle
149161
To enforce checksyle conventions add the checkstyle plugin and include a dependency on `spring-javaformat-checkstyle`:
150162

@@ -175,6 +187,7 @@ Your `checkstyle.xml` file should look then like this:
175187
----
176188

177189

190+
178191
=== Eclipse
179192
The Eclipse plugin provides a custom formatter implementation and automatically applies project specific settings.
180193
The plugin is automatically activated whenever the Maven or Gradle plugins are discovered in a project build script.
@@ -195,6 +208,8 @@ You can download the latest version from
195208
https://repo.spring.io/release/io/spring/javaformat/io.spring.javaformat.eclipse.site/{release-version}[repo.spring.io]
196209
or use the https://repo.spring.io/javaformat-eclipse-update-site/[update site].
197210

211+
212+
198213
=== IntelliJ IDEA
199214
The IntelliJ IDEA plugin provides custom formatter support for IntelliJ IDEA.
200215
The plugin is automatically activated whenever the Maven or Gradle plugins are discovered in a project build script.
@@ -204,15 +219,21 @@ You can use the standard `code` -> `reformat code` action to format the code.
204219
To install the plugin use the `spring-javaformat-intellij-idea-plugin` jar file.
205220
You can download the latest version from https://repo.spring.io/release/io/spring/javaformat/spring-javaformat-intellij-idea-plugin/{release-version}[repo.spring.io].
206221

207-
=== About the conventions
222+
223+
224+
=== About the Conventions
208225
Most of the coding conventions and style comes from the Spring Framework and Spring Boot projects.
209226
Spring Framework manually formats code, where as Spring Boot uses automatic formatting.
210227

228+
229+
211230
=== Tips
212231
Formatting and Checkstyle alone are not enough to produce truly consistent code.
213232
Here are some tips that we've found useful when developing Spring Boot.
214233

215-
==== Excluding specific checks
234+
235+
236+
==== Excluding Specific Checks
216237
If you want most `SpringChecks` but need to exclude one or two, you can do something like this in your `checkstyle.xml`:
217238

218239
[source,xml,indent=0]
@@ -228,7 +249,9 @@ If you want most `SpringChecks` but need to exclude one or two, you can do somet
228249
</module>
229250
----
230251

231-
==== Disabling formatting for blocks of code
252+
253+
254+
==== Disabling Formatting For Blocks of Code
232255
Some code isn't particularly amenable to automatic formatting.
233256
For example, Spring Security configurations often work better when manually formatted.
234257

@@ -243,6 +266,8 @@ If you need to disable formatting for a specific block of code you can enclose i
243266
// @formatter:on
244267
----
245268

269+
270+
246271
==== Wrapping
247272
The source formatter uses 120 chars for wrapping. This aims to strike a balance between
248273
making use of available horizontal space in your IDE and avoiding unwanted additional
@@ -254,23 +279,31 @@ code bunched up to the right of your screen you should take that as a signal to
254279
"`extract method`" refactor. Extracting small private methods will improve formatting and
255280
it helps when reading the code and debugging.
256281

282+
283+
257284
==== Whitespace
258285
Keeping whitespace lines out of method bodies can help make the code easier to scan.
259286
If blank lines are only included between methods it becomes easier to see the overall structure of the class.
260287
If you find you need whitespace inside your method, consider if extracting a private method might give a better result.
261288

289+
290+
262291
==== Comments
263292
Try to add javadoc for each public method and constant.
264293
Private methods shouldn't generally need javadoc, unless it provides a natural place to document unusual behavior.
265294

266295
The checkstyle rules will enforce that all public classes have javadoc.
267296
They will also ensure that `@author` tags are well formed.
268297

298+
299+
269300
==== Final
270301
Private members should be `final` whenever possible.
271302
Local variable and parameters should generally not be explicitly declared as final since it adds so much noise.
272303

273-
==== Read-down methods, fields and parameters
304+
305+
306+
==== Read-down Methods, Fields and Parameters
274307
Methods don't need to be organized by scope.
275308
There's no need to group all `private`, `protected` and `public` methods together.
276309
Instead try to make your code easy to read when scanning the file from top to bottom.

0 commit comments

Comments
 (0)