pmd代碼檢測規則修改
以下是一份pmd的rules文件
[html] view plain copy
<?xml
version="1.0"?>
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Android Application Rules"
- xmlns="http://pmd.sf.net/ruleset/1.0.0"
- xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
- xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
>
<description>
Custom ruleset for ribot Android application</description>
<exclude-pattern>
.*/R.java</exclude-pattern>
<exclude-pattern>
.*/gen/.*</exclude-pattern>
<rule
ref="rulesets/java/android.xml"/>
<rule
ref="rulesets/java/clone.xml"
/>
<rule
ref="rulesets/java/finalizers.xml"/>
<rule
ref="rulesets/java/imports.xml">
- <!-- Espresso is designed this way !-->
<exclude
name="TooManyStaticImports"/>
</rule>
<rule
ref="rulesets/java/logging-java.xml">
- <!-- This rule wasn"t working properly and given errors in every var call info -->
<exclude
name="GuardLogStatementJavaUtil"/>
</rule>
<rule
ref="rulesets/java/braces.xml">
- <!-- We allow single line if"s without braces -->
<exclude
name="IfStmtsMustUseBraces"/>
</rule>
<rule
ref="rulesets/java/strings.xml">
- <!-- Exclude because causes problems with SQL Strings that usually require duplication -->
<exclude
name="AvoidDuplicateLiterals"/>
</rule>
<rule
ref="rulesets/java/basic.xml"/>
<rule
ref="rulesets/java/naming.xml">
<exclude
name="AbstractNaming"/>
<exclude
name="LongVariable"
/>
<exclude
name="ShortMethodName"/>
<exclude
name="ShortVariable"/>
<exclude
name="ShortClassName"/>
<exclude
name="VariableNamingConventions"/>
</rule>
</ruleset>
這次主要講的是怎麼移除已有的規則(由於if嵌套需要合併的規則感覺不合理所以今天研究了一下怎麼將這一條規則移除);
首先我們看一張官網上的規則分類圖:
由以上這張圖可以知道,pmd規則是由幾大類構成,每個大類下面又有細則,所以我想要將我不要的規則移除的話,首先我要找到歸屬的大類,假如我報錯的地方點進來是對應著ForLoopShouldBeWhileLoop這個,那麼我們只需要將
<rule ref="rulesets/java/basic.xml" />
這段改為
<rule ref="rulesets/java/basic.xml">
<exclude name="ForLoopShouldBeWhileLoop" />
</rule>
是不是超級簡單哈~~~~主要是exclude關鍵字在起作用哦~~
TAG:程序員小新人學習 |