pmd-ruleset.xml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?xml version="1.0"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing,
  12. software distributed under the License is distributed on an
  13. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. KIND, either express or implied. See the License for the
  15. specific language governing permissions and limitations
  16. under the License.
  17. -->
  18. <ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Default Maven PMD Plugin Ruleset" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
  19. <description>
  20. GeoTools ruleset. See https://pmd.github.io/latest/pmd_userdocs_understanding_rulesets.html
  21. </description>
  22. <rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP"/>
  23. <rule ref="category/java/bestpractices.xml/CheckResultSet"/>
  24. <rule ref="category/java/bestpractices.xml/UnusedLocalVariable"/>
  25. <rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
  26. <rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
  27. <rule ref="category/java/bestpractices.xml/SystemPrintln"/>
  28. <rule ref="category/java/bestpractices.xml/ForLoopCanBeForeach" />
  29. <rule ref="category/java/bestpractices.xml/UseTryWithResources" >
  30. <description>
  31. Use try-with-resources to avoid memory / resources leaks.
  32. </description>
  33. <properties>
  34. <!-- The rule reports false positives for closeable arguments that are used -->
  35. <!-- closed within the method body. This suppression tries to avoid false positives for -->
  36. <!-- this case, until we can switch to Java 9 and just use try(variable) {...} without -->
  37. <!-- the need to instatiate the variable in the try -->
  38. <property name="violationSuppressXPath">
  39. <value>
  40. <![CDATA[
  41. ./FinallyStatement//Name[
  42. substring-after(@Image, '.') = 'close' or
  43. substring-after(@Image, '.') = 'closeQuietly'
  44. ]
  45. [ pmd-java:typeIs('java.lang.AutoCloseable') and
  46. fn:substring-before(@Image, '.') = ancestor::MethodDeclaration/MethodDeclarator//VariableDeclaratorId/@Name
  47. ]"/>
  48. ]]>
  49. </value>
  50. </property>
  51. </properties>
  52. </rule>
  53. <rule ref="category/java/bestpractices.xml/ReplaceHashtableWithMap" />
  54. <rule ref="category/java/bestpractices.xml/ReplaceVectorWithList" />
  55. <rule ref="category/java/bestpractices.xml/AvoidPrintStackTrace" />
  56. <rule ref="category/java/bestpractices.xml/MissingOverride" />
  57. <rule ref="category/java/bestpractices.xml/UseStandardCharsets" />
  58. <rule ref="category/java/performance.xml/UseArrayListInsteadOfVector" />
  59. <rule ref="category/java/codestyle.xml/ExtendsObject"/>
  60. <rule ref="category/java/codestyle.xml/ForLoopShouldBeWhileLoop"/>
  61. <rule ref="category/java/codestyle.xml/UnnecessaryFullyQualifiedName"/>
  62. <rule ref="category/java/codestyle.xml/UseDiamondOperator" />
  63. <rule ref="category/java/codestyle.xml/UnnecessaryReturn"/>
  64. <rule ref="category/java/codestyle.xml/UselessParentheses"/>
  65. <rule ref="category/java/codestyle.xml/UselessQualifiedThis"/>
  66. <rule ref="category/java/codestyle.xml/UnnecessaryCast" />
  67. <rule ref="category/java/codestyle.xml/IdenticalCatchBranches" />
  68. <rule ref="category/java/codestyle.xml/UseShortArrayInitializer" />
  69. <rule ref="category/java/codestyle.xml/UnnecessaryImport" />
  70. <rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor"/>
  71. <rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators"/>
  72. <rule ref="category/java/errorprone.xml/AvoidUsingOctalValues"/>
  73. <rule ref="category/java/errorprone.xml/BrokenNullCheck"/>
  74. <rule ref="category/java/errorprone.xml/CheckSkipResult"/>
  75. <rule ref="category/java/errorprone.xml/ClassCastExceptionWithToArray"/>
  76. <rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices"/>
  77. <rule ref="category/java/errorprone.xml/EmptyFinallyBlock"/>
  78. <rule ref="category/java/errorprone.xml/EmptyIfStmt"/>
  79. <rule ref="category/java/errorprone.xml/EmptyInitializer"/>
  80. <rule ref="category/java/errorprone.xml/EmptyStatementBlock"/>
  81. <rule ref="category/java/errorprone.xml/EmptyStatementNotInLoop"/>
  82. <rule ref="category/java/errorprone.xml/EmptySwitchStatements"/>
  83. <rule ref="category/java/errorprone.xml/EmptySynchronizedBlock"/>
  84. <rule ref="category/java/errorprone.xml/EmptyTryBlock"/>
  85. <rule ref="category/java/errorprone.xml/EmptyWhileStmt"/>
  86. <rule ref="category/java/errorprone.xml/JumbledIncrementer"/>
  87. <rule ref="category/java/errorprone.xml/MisplacedNullCheck"/>
  88. <rule ref="category/java/errorprone.xml/OverrideBothEqualsAndHashcode"/>
  89. <rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock"/>
  90. <rule ref="category/java/errorprone.xml/UnconditionalIfStatement"/>
  91. <rule ref="category/java/errorprone.xml/UnnecessaryConversionTemporary"/>
  92. <rule ref="category/java/errorprone.xml/UnusedNullCheckInEquals"/>
  93. <rule ref="category/java/errorprone.xml/UselessOperationOnImmutable"/>
  94. <rule ref="category/java/errorprone.xml/CloseResource">
  95. <properties>
  96. <!-- When calling the store to close, PMD wants the full prefix before the call to -->
  97. <!-- the method to match, so let's try to use common var names for store ... -->
  98. <property name="closeTargets" value="releaseConnection,store.releaseConnection,closeQuietly,closeConnection,closeSafe,store.closeSafe,dataStore.closeSafe,getDataStore().closeSafe,close,closeResultSet,closeStmt,closeFinally,JDBCUtils.close"/>
  99. <property name="allowedResourceTypes" value="java.io.ByteArrayOutputStream|java.io.ByteArrayInputStream|java.io.StringWriter|java.io.CharArrayWriter|java.util.stream.Stream|java.util.stream.IntStream|java.util.stream.LongStream|java.util.stream.DoubleStream|java.io.StringReader" />
  100. </properties>
  101. </rule>
  102. <rule ref="category/java/multithreading.xml/AvoidThreadGroup"/>
  103. <rule ref="category/java/multithreading.xml/DontCallThreadRun"/>
  104. <rule ref="category/java/multithreading.xml/DoubleCheckedLocking"/>
  105. <rule ref="category/java/performance.xml/BigIntegerInstantiation"/>
  106. <rule ref="category/java/bestpractices.xml/PrimitiveWrapperInstantiation"/>
  107. <rule ref="category/java/performance.xml/StringInstantiation"/>
  108. <rule name="wildcards" language="java" message="No Wildcard Imports" class="net.sourceforge.pmd.lang.rule.XPathRule">
  109. <description>
  110. Don't use wildcard imports
  111. </description>
  112. <priority>3</priority>
  113. <properties>
  114. <property name="version" value="2.0"/>
  115. <property name="xpath">
  116. <value><![CDATA[
  117. //ImportDeclaration[@ImportedName=@PackageName]
  118. ]]></value>
  119. </property>
  120. </properties>
  121. </rule>
  122. <rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty" />
  123. <rule ref="category/java/design.xml/CognitiveComplexity">
  124. <properties>
  125. <property name="reportLevel" value="130"/>
  126. </properties>
  127. </rule>
  128. </ruleset>