[3.4.0-map-sdk] add pmd rule set

This commit is contained in:
zhongchao
2023-09-18 19:01:52 +08:00
parent e374bf37a6
commit 51f38ae919
3 changed files with 68 additions and 2 deletions

View File

@@ -0,0 +1,41 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Custom ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
This ruleset checks my code for bad stuff
</description>
<!--https://pmd.github.io/pmd-5.6.1/pmd-java/index.html-->
<exclude-pattern>.*/R.java</exclude-pattern>
<exclude-pattern>.*/gen/.*</exclude-pattern>
<exclude-pattern>.*Dagger*.*</exclude-pattern>
<!-- 容易出现运行时错误 -->
<rule ref="category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop" />
<rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor" />
<rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators" />
<rule ref="category/java/errorprone.xml/AvoidUsingOctalValues" />
<rule ref="category/java/errorprone.xml/BrokenNullCheck" />
<rule ref="category/java/errorprone.xml/CheckSkipResult" />
<rule ref="category/java/errorprone.xml/ClassCastExceptionWithToArray" />
<rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices" />
<rule ref="category/java/errorprone.xml/JumbledIncrementer" />
<rule ref="category/java/errorprone.xml/MisplacedNullCheck" />
<rule ref="category/java/errorprone.xml/OverrideBothEqualsAndHashcode" />
<rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock" />
<rule ref="category/java/errorprone.xml/UnconditionalIfStatement" />
<rule ref="category/java/errorprone.xml/UnnecessaryConversionTemporary" />
<rule ref="category/java/errorprone.xml/UnusedNullCheckInEquals" />
<rule ref="category/java/errorprone.xml/UselessOperationOnImmutable" />
<!-- 多线程时问题-->
<rule ref="category/java/multithreading.xml/AvoidThreadGroup" />
<rule ref="category/java/multithreading.xml/DontCallThreadRun" />
<rule ref="category/java/multithreading.xml/DoubleCheckedLocking" />
<!-- 需要优化代码的地方-->
<rule ref="category/java/performance.xml/BigIntegerInstantiation" />
<!-- 安全问题-->
<rule ref="category/java/security.xml" />
</ruleset>

View File

@@ -1 +1,25 @@
//apply plugin:"pmd"
apply plugin: "pmd"
def pmdConfigPath = rootProject.file("codequality").path
task pmd(type:Pmd){
//忽略失败如果设置为true检测出bug会停止task
ignoreFailures = false
consoleOutput = true
//filter路径
ruleSetFiles = files("${pmdConfigPath}/custom-pmd-ruleset.xml") // todo 新增rules
ruleSets = []
//检测资源路径
source 'src/main/java','src/jinlvvan/java','src/driverm1/java'
//排除项
exclude '**/gen/**'
reports {
xml.getRequired().set(false)
html.getRequired().set(true)
//结果输出到项目根目录下的 build/reports/pmd 文件夹中只需要html格式的结果文档
def destination = new File(new File("${project.rootProject.buildDir.path}/reports/pmd"), "${project.name}-pmd.html")
html.destination(destination)
}
}