Add checkstyle rule for List.of() / Set.of() / Map.of()

This commits adds a checkstyle rule to not use List.of(), Set.of()
and Map.of(), preferring Collections.emptyList(), emptySet(), and
emptyMap() respectively.

It replaces usages of these methods across the codebase.

See gh-32655
This commit is contained in:
Bertolt Meier
2022-10-10 12:35:32 +02:00
committed by Andy Wilkinson
parent 7626de4e91
commit 647a2905c8
10 changed files with 34 additions and 15 deletions

View File

@@ -54,6 +54,13 @@
value="Please use BDD-style (given, when, then) using BDDMockito imports." />
<property name="ignoreComments" value="true" />
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
<property name="maximum" value="0"/>
<property name="format" value="(List|Map|Set)\.of\(\)" />
<property name="message"
value="Please use Collections.emptyList()/emptyMap()/emptySet() for creating empty lists/maps/sets." />
<property name="ignoreComments" value="true" />
</module>
<module name="io.spring.javaformat.checkstyle.check.SpringJavadocCheck">
<property name="publicOnlySinceTags" value="true" />
<property name="requireSinceTag" value="true" />