Skip to content

Commit 4eef9ec

Browse files
committed
Improve Code Analysis
See xdev-software/java-template#13
1 parent 8f6df23 commit 4eef9ec

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

.config/checkstyle/checkstyle.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<module name="TreeWalker">
5353
<!-- Checks - sorted alphabetically -->
5454
<module name="ArrayTypeStyle"/>
55+
<module name="AvoidDoubleBraceInitialization"/>
5556
<module name="AvoidStarImport"/>
5657
<module name="ConstantName"/>
5758
<module name="DefaultComesLast"/>
@@ -68,6 +69,11 @@
6869
<module name="FinalParameters"/>
6970
<module name="GenericWhitespace"/>
7071
<module name="HideUtilityClassConstructor"/>
72+
<module name="IllegalCatch">
73+
<!-- https://docs.pmd-code.org/pmd-doc-7.11.0/pmd_rules_java_errorprone.html#avoidcatchingnpe -->
74+
<!-- https://docs.pmd-code.org/pmd-doc-7.11.0/pmd_rules_java_errorprone.html#avoidcatchingthrowable -->
75+
<property name="illegalClassNames" value="Error,Throwable,NullPointerException,java.lang.Error,java.lang.Throwable,java.lang.NullPointerException"/>
76+
</module>
7177
<module name="IllegalImport"/>
7278
<module name="InterfaceIsType"/>
7379
<module name="JavadocStyle">
@@ -93,7 +99,6 @@
9399
<module name="MethodParamPad"/>
94100
<module name="MissingDeprecated"/>
95101
<module name="MissingOverride"/>
96-
<module name="MissingSwitchDefault"/>
97102
<module name="ModifierOrder"/>
98103
<module name="NeedBraces"/>
99104
<module name="NoClone"/>
@@ -122,7 +127,13 @@
122127
</module>
123128
<module name="TypecastParenPad"/>
124129
<module name="TypeName"/>
130+
<module name="UnnecessaryParentheses"/>
131+
<module name="UnnecessarySemicolonAfterOuterTypeDeclaration"/>
132+
<module name="UnnecessarySemicolonAfterTypeMemberDeclaration"/>
133+
<module name="UnnecessarySemicolonInEnumeration"/>
134+
<module name="UnnecessarySemicolonInTryWithResources"/>
125135
<module name="UnusedImports"/>
136+
<module name="UnusedLocalVariable"/>
126137
<module name="UpperEll"/>
127138
<module name="VisibilityModifier">
128139
<property name="packageAllowed" value="true"/>

.config/pmd/ruleset.xml

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,38 @@
1010

1111
<!-- Only rules that don't overlap with CheckStyle! -->
1212

13+
<rule ref="category/java/bestpractices.xml/AvoidPrintStackTrace"/>
14+
<rule ref="category/java/bestpractices.xml/AvoidStringBufferField"/>
1315
<rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP"/>
16+
<rule ref="category/java/bestpractices.xml/ConstantsInInterface"/>
17+
<rule ref="category/java/bestpractices.xml/ExhaustiveSwitchHasDefault"/>
18+
<rule ref="category/java/bestpractices.xml/LiteralsFirstInComparisons"/>
19+
<!-- CheckStyle can't handle this switch behavior -> delegated to PMD -->
20+
<rule ref="category/java/bestpractices.xml/NonExhaustiveSwitch"/>
21+
<rule ref="category/java/bestpractices.xml/OneDeclarationPerLine">
22+
<properties>
23+
<property name="strictMode" value="true"/>
24+
</properties>
25+
</rule>
1426
<rule ref="category/java/bestpractices.xml/PreserveStackTrace"/>
27+
<rule ref="category/java/bestpractices.xml/SimplifiableTestAssertion"/>
28+
<rule ref="category/java/bestpractices.xml/SystemPrintln"/>
29+
<rule ref="category/java/bestpractices.xml/UnusedAssignment"/>
30+
<rule ref="category/java/bestpractices.xml/UnusedFormalParameter"/>
31+
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
32+
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
1533
<rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty"/>
34+
<rule ref="category/java/bestpractices.xml/UseEnumCollections"/>
1635
<rule ref="category/java/bestpractices.xml/UseStandardCharsets"/>
36+
<rule ref="category/java/bestpractices.xml/UseTryWithResources"/>
1737

1838
<!-- Native code is platform dependent; Loading external native libs might pose a security threat -->
1939
<rule ref="category/java/codestyle.xml/AvoidUsingNativeCode"/>
2040
<rule ref="category/java/codestyle.xml/IdenticalCatchBranches"/>
41+
<rule ref="category/java/codestyle.xml/LambdaCanBeMethodReference"/>
2142
<rule ref="category/java/codestyle.xml/NoPackage"/>
2243
<rule ref="category/java/codestyle.xml/PrematureDeclaration"/>
44+
<rule ref="category/java/codestyle.xml/UnnecessarySemicolon"/>
2345

2446
<rule ref="category/java/design.xml">
2547
<!-- Sometimes abstract classes have just fields -->
@@ -76,9 +98,6 @@
7698

7799
<!-- Limit too low -->
78100
<exclude name="UseObjectForClearerAPI"/>
79-
80-
<!-- Handled by checkstyle -->
81-
<exclude name="UseUtilityClass"/>
82101
</rule>
83102

84103
<rule ref="category/java/design.xml/AvoidDeeplyNestedIfStmts">
@@ -114,17 +133,33 @@
114133
</properties>
115134
</rule>
116135

136+
<rule ref="category/java/errorprone.xml/AssignmentToNonFinalStatic"/>
137+
<rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor"/>
138+
<rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators"/>
117139
<rule ref="category/java/errorprone.xml/AvoidUsingOctalValues"/>
118140
<rule ref="category/java/errorprone.xml/BrokenNullCheck"/>
119141
<rule ref="category/java/errorprone.xml/ComparisonWithNaN"/>
120142
<rule ref="category/java/errorprone.xml/DoNotCallGarbageCollectionExplicitly"/>
121143
<rule ref="category/java/errorprone.xml/DontImportSun"/>
144+
<rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices"/>
145+
<rule ref="category/java/errorprone.xml/EqualsNull"/>
146+
<rule ref="category/java/errorprone.xml/IdempotentOperations"/>
147+
<rule ref="category/java/errorprone.xml/ImplicitSwitchFallThrough"/>
148+
<rule ref="category/java/errorprone.xml/InstantiationToGetClass"/>
149+
<rule ref="category/java/errorprone.xml/InvalidLogMessageFormat"/>
150+
<rule ref="category/java/errorprone.xml/JumbledIncrementer"/>
122151
<rule ref="category/java/errorprone.xml/MisplacedNullCheck"/>
152+
<rule ref="category/java/errorprone.xml/MoreThanOneLogger"/>
153+
<rule ref="category/java/errorprone.xml/NonStaticInitializer"/>
154+
<rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock"/>
155+
<rule ref="category/java/errorprone.xml/SingletonClassReturningNewInstance"/>
156+
<rule ref="category/java/errorprone.xml/UnconditionalIfStatement"/>
123157
<rule ref="category/java/errorprone.xml/UnnecessaryCaseChange"/>
158+
<rule ref="category/java/errorprone.xml/UselessOperationOnImmutable"/>
124159

125160

126161
<rule ref="category/java/multithreading.xml">
127-
<!-- Just bloats code -->
162+
<!-- Just bloats code; improved in JEP-491/Java 24+ -->
128163
<exclude name="AvoidSynchronizedAtMethodLevel"/>
129164

130165
<!-- NOPE -->

0 commit comments

Comments
 (0)