@@ -149,8 +149,10 @@ or apply the formatting to the files.
149149
150150Available formatting steps:
151151 clang-format Runs clang-format
152- license-header Runs license header
152+ format-annotations Corrects line break formatting of type annotations in
153+ java files.
153154 google-java-format Runs google java format
155+ license-header Runs license header
154156 palantir-java-format Runs palantir java format
155157 prettier Runs prettier, the opinionated code formatter.
156158
@@ -177,6 +179,7 @@ Possible exit codes:
177179Spotless CLI supports the following formatter steps in alphabetical order:
178180
179181- [ clang-format] ( #clang-format )
182+ - [ format-annotations] ( #format-annotations )
180183- [ google-java-format] ( #google-java-format )
181184- [ license-header] ( #license-header )
182185- [ palantir-java-format] ( #palantir-java-format )
@@ -220,6 +223,56 @@ spotless --target '**/src/**/*.cpp' clang-format --clang-version=20.1.2 --style=
220223> [ !IMPORTANT]
221224> Running a clang-format step requires a working installation of the clang-format binary.
222225
226+ ### format-annotations
227+
228+ TODO: maybe list possible target file types - maybe in the shields?
229+
230+ In Java, type annotations should be on the same line as the type that they qualify. This formatter fixes this for you.
231+
232+ To see usage instructions for the format-annotations formatter, run: ` spotless format-annotations --help `
233+
234+ <!-- -freshmark usage_format_annotations
235+ output =
236+ '```\n' +
237+ {{usage.format-annotations.array}}.join('\n') +
238+ '\n```';
239+ -->
240+
241+ ```
242+ Usage: spotless format-annotations [-hV] [-a[=annotation[,
243+ annotation...]...]]... [-r[=annotation[,
244+ annotation...]...]]...
245+ Corrects line break formatting of type annotations in java files.
246+ -a, --add-type-annotation[=annotation[,annotation...]...]
247+ Add annotations to the list of type annotations to keep on
248+ the same line as the type.
249+ -h, --help Show this help message and exit.
250+ -r, --remove-type-annotation[=annotation[,annotation...]...]
251+ Remove annotations from the list of type annotations to keep
252+ on the same line as the type.
253+ -V, --version Print version information and exit.
254+ ```
255+
256+ <!-- -freshmark /usage_format_annotations -->
257+
258+ Example usage:
259+
260+ ``` shell
261+ spotless --target ' **/src/**/*.java' format-annotations
262+
263+ # or add/remove annotations to the default set using list syntax
264+ spotless --target ' **/src/**/*.java' format-annotations \
265+ --add-type-annotation=' MyAnnotation1,MyAnnotation2' \
266+ --remove-type-annotation=' MyAnnotation3,MyAnnotation4'
267+
268+ # or add/remove annotations to the default set using repeated options
269+ spotless --target ' **/src/**/*.java' format-annotations \
270+ --add-type-annotation=' MyAnnotation1' \
271+ --add-type-annotation=' MyAnnotation2' \
272+ --remove-type-annotation=' MyAnnotation3' \
273+ --remove-type-annotation=' MyAnnotation4'
274+ ```
275+
223276### google-java-format
224277
225278<!-- -freshmark gjfshields
0 commit comments