|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<ruleset name="Default" |
| 3 | + xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" |
| 4 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 5 | + xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd"> |
| 6 | + |
| 7 | + <description> |
| 8 | + This ruleset checks the code for discouraged programming constructs. |
| 9 | + </description> |
| 10 | + |
| 11 | + <!-- Only rules that don't overlap with CheckStyle! --> |
| 12 | + |
| 13 | + <rule ref="category/java/bestpractices.xml/AvoidPrintStackTrace"/> |
| 14 | + <rule ref="category/java/bestpractices.xml/AvoidStringBufferField"/> |
| 15 | + <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> |
| 26 | + <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"/> |
| 33 | + <rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty"/> |
| 34 | + <rule ref="category/java/bestpractices.xml/UseEnumCollections"/> |
| 35 | + <rule ref="category/java/bestpractices.xml/UseStandardCharsets"/> |
| 36 | + <rule ref="category/java/bestpractices.xml/UseTryWithResources"/> |
| 37 | + |
| 38 | + <!-- Native code is platform dependent; Loading external native libs might pose a security threat --> |
| 39 | + <rule ref="category/java/codestyle.xml/AvoidUsingNativeCode"/> |
| 40 | + <rule ref="category/java/codestyle.xml/IdenticalCatchBranches"/> |
| 41 | + <rule ref="category/java/codestyle.xml/LambdaCanBeMethodReference"/> |
| 42 | + <rule ref="category/java/codestyle.xml/NoPackage"/> |
| 43 | + <rule ref="category/java/codestyle.xml/PrematureDeclaration"/> |
| 44 | + <rule ref="category/java/codestyle.xml/UnnecessarySemicolon"/> |
| 45 | + |
| 46 | + <rule ref="category/java/design.xml"> |
| 47 | + <!-- Sometimes abstract classes have just fields --> |
| 48 | + <exclude name="AbstractClassWithoutAnyMethod"/> |
| 49 | + |
| 50 | + <!-- Using RuntimeExceptions is ok --> |
| 51 | + <exclude name="AvoidCatchingGenericException"/> |
| 52 | + <exclude name="AvoidThrowingRawExceptionTypes"/> |
| 53 | + |
| 54 | + <!-- Limit too low --> |
| 55 | + <exclude name="AvoidDeeplyNestedIfStmts"/> |
| 56 | + |
| 57 | + <!-- Limit too low --> |
| 58 | + <exclude name="CouplingBetweenObjects"/> |
| 59 | + |
| 60 | + <!-- Limit too low --> |
| 61 | + <exclude name="CyclomaticComplexity"/> |
| 62 | + |
| 63 | + <!-- Makes entity classes impossible --> |
| 64 | + <exclude name="DataClass"/> |
| 65 | + |
| 66 | + <!-- Used commonly particular in bigger methods with upstream throws --> |
| 67 | + <exclude name="ExceptionAsFlowControl"/> |
| 68 | + |
| 69 | + <!-- Limit too low --> |
| 70 | + <exclude name="ExcessiveImports"/> |
| 71 | + |
| 72 | + <!-- Handled by TooManyFields/TooManyMethods --> |
| 73 | + <exclude name="ExcessivePublicCount"/> |
| 74 | + |
| 75 | + <!-- Prohibits accessing members using multiple depths --> |
| 76 | + <exclude name="LawOfDemeter"/> |
| 77 | + |
| 78 | + <!-- No effect --> |
| 79 | + <exclude name="LoosePackageCoupling"/> |
| 80 | + |
| 81 | + <!-- Prohibits singleton pattern --> |
| 82 | + <exclude name="MutableStaticState"/> |
| 83 | + |
| 84 | + <!-- Checks LoC, already handled by Checkstyle --> |
| 85 | + <exclude name="NcssCount"/> |
| 86 | + |
| 87 | + <!-- Some override methods or Junit require this --> |
| 88 | + <exclude name="SignatureDeclareThrowsException"/> |
| 89 | + |
| 90 | + <!-- Reports FP for equals methods --> |
| 91 | + <exclude name="SimplifyBooleanReturns"/> |
| 92 | + |
| 93 | + <!-- Limit too low --> |
| 94 | + <exclude name="TooManyFields"/> |
| 95 | + |
| 96 | + <!-- Limit too low --> |
| 97 | + <exclude name="TooManyMethods"/> |
| 98 | + |
| 99 | + <!-- Limit too low --> |
| 100 | + <exclude name="UseObjectForClearerAPI"/> |
| 101 | + </rule> |
| 102 | + |
| 103 | + <rule ref="category/java/design.xml/AvoidDeeplyNestedIfStmts"> |
| 104 | + <properties> |
| 105 | + <property name="problemDepth" value="4"/> |
| 106 | + </properties> |
| 107 | + </rule> |
| 108 | + <rule ref="category/java/design.xml/CouplingBetweenObjects"> |
| 109 | + <properties> |
| 110 | + <property name="threshold" value="100"/> |
| 111 | + </properties> |
| 112 | + </rule> |
| 113 | + <rule ref="category/java/design.xml/CyclomaticComplexity"> |
| 114 | + <properties> |
| 115 | + <property name="classReportLevel" value="150"/> |
| 116 | + <property name="methodReportLevel" value="25"/> |
| 117 | + <property name="cycloOptions" value=""/> |
| 118 | + </properties> |
| 119 | + </rule> |
| 120 | + <rule ref="category/java/design.xml/ExcessiveImports"> |
| 121 | + <properties> |
| 122 | + <property name="minimum" value="200"/> |
| 123 | + </properties> |
| 124 | + </rule> |
| 125 | + <rule ref="category/java/design.xml/TooManyFields"> |
| 126 | + <properties> |
| 127 | + <property name="maxfields" value="50"/> |
| 128 | + </properties> |
| 129 | + </rule> |
| 130 | + <rule ref="category/java/design.xml/TooManyMethods"> |
| 131 | + <properties> |
| 132 | + <property name="maxmethods" value="100"/> |
| 133 | + </properties> |
| 134 | + </rule> |
| 135 | + |
| 136 | + <rule ref="category/java/errorprone.xml/AssignmentToNonFinalStatic"/> |
| 137 | + <rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor"/> |
| 138 | + <rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators"/> |
| 139 | + <rule ref="category/java/errorprone.xml/AvoidUsingOctalValues"/> |
| 140 | + <rule ref="category/java/errorprone.xml/BrokenNullCheck"/> |
| 141 | + <rule ref="category/java/errorprone.xml/ComparisonWithNaN"/> |
| 142 | + <rule ref="category/java/errorprone.xml/DoNotCallGarbageCollectionExplicitly"/> |
| 143 | + <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"/> |
| 151 | + <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"/> |
| 157 | + <rule ref="category/java/errorprone.xml/UnnecessaryCaseChange"/> |
| 158 | + <rule ref="category/java/errorprone.xml/UselessOperationOnImmutable"/> |
| 159 | + |
| 160 | + |
| 161 | + <rule ref="category/java/multithreading.xml"> |
| 162 | + <!-- Just bloats code; improved in JEP-491/Java 24+ --> |
| 163 | + <exclude name="AvoidSynchronizedAtMethodLevel"/> |
| 164 | + |
| 165 | + <!-- NOPE --> |
| 166 | + <exclude name="DoNotUseThreads"/> |
| 167 | + |
| 168 | + <!-- Doesn't detect nested thread safe singleton pattern --> |
| 169 | + <exclude name="NonThreadSafeSingleton"/> |
| 170 | + |
| 171 | + <!-- Should relevant for fields that use multithreading which is rare --> |
| 172 | + <exclude name="UseConcurrentHashMap"/> |
| 173 | + </rule> |
| 174 | + |
| 175 | + <rule ref="category/java/performance.xml"> |
| 176 | + <!-- This was fixed in Java 10 --> |
| 177 | + <exclude name="AvoidFileStream"/> |
| 178 | + |
| 179 | + <!-- Used everywhere and has neglectable performance impact --> |
| 180 | + <exclude name="AvoidInstantiatingObjectsInLoops"/> |
| 181 | + |
| 182 | + <!-- Handled by checkstyle --> |
| 183 | + <exclude name="RedundantFieldInitializer"/> |
| 184 | + |
| 185 | + <!-- Nowadays optimized by compiler; No code bloating needed --> |
| 186 | + <exclude name="UseStringBufferForStringAppends"/> |
| 187 | + </rule> |
| 188 | + |
| 189 | + <rule ref="category/java/performance.xml/TooFewBranchesForSwitch"> |
| 190 | + <properties> |
| 191 | + <!-- If you have one case only please use a if --> |
| 192 | + <property name="minimumNumberCaseForASwitch" value="2"/> |
| 193 | + </properties> |
| 194 | + </rule> |
| 195 | + |
| 196 | + <rule ref="category/java/security.xml"/> |
| 197 | +</ruleset> |
0 commit comments