當前位置:
首頁 > 知識 > pmd代碼檢測規則修改

pmd代碼檢測規則修改

以下是一份pmd的rules文件

[html] view plain copy

  1. <?xml

    version="1.0"

    ?>

  2. <ruleset

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Android Application Rules"

  3. xmlns="http://pmd.sf.net/ruleset/1.0.0"
  4. xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
  5. xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"

    >

  6. <description>

    Custom ruleset for ribot Android application

    </description>

  7. <exclude-pattern>

    .*/R.java

    </exclude-pattern>

  8. <exclude-pattern>

    .*/gen/.*

    </exclude-pattern>

  9. <rule

    ref="rulesets/java/android.xml"

    />

  10. <rule

    ref="rulesets/java/clone.xml"

    />

  11. <rule

    ref="rulesets/java/finalizers.xml"

    />

  12. <rule

    ref="rulesets/java/imports.xml"

    >

  13. <!-- Espresso is designed this way !-->
  14. <exclude

    name="TooManyStaticImports"

    />

  15. </rule>

  16. <rule

    ref="rulesets/java/logging-java.xml"

    >

  17. <!-- This rule wasn"t working properly and given errors in every var call info -->
  18. <exclude

    name="GuardLogStatementJavaUtil"

    />

  19. </rule>

  20. <rule

    ref="rulesets/java/braces.xml"

    >

  21. <!-- We allow single line if"s without braces -->
  22. <exclude

    name="IfStmtsMustUseBraces"

    />

  23. </rule>

  24. <rule

    ref="rulesets/java/strings.xml"

    >

  25. <!-- Exclude because causes problems with SQL Strings that usually require duplication -->
  26. <exclude

    name="AvoidDuplicateLiterals"

    />

  27. </rule>

  28. <rule

    ref="rulesets/java/basic.xml"

    />

  29. <rule

    ref="rulesets/java/naming.xml"

    >

  30. <exclude

    name="AbstractNaming"

    />

  31. <exclude

    name="LongVariable"

    />

  32. <exclude

    name="ShortMethodName"

    />

  33. <exclude

    name="ShortVariable"

    />

  34. <exclude

    name="ShortClassName"

    />

  35. <exclude

    name="VariableNamingConventions"

    />

  36. </rule>

  37. </ruleset>

這次主要講的是怎麼移除已有的規則(由於if嵌套需要合併的規則感覺不合理所以今天研究了一下怎麼將這一條規則移除);

首先我們看一張官網上的規則分類圖:

pmd代碼檢測規則修改

由以上這張圖可以知道,pmd規則是由幾大類構成,每個大類下面又有細則,所以我想要將我不要的規則移除的話,首先我要找到歸屬的大類,假如我報錯的地方點進來是對應著ForLoopShouldBeWhileLoop這個,那麼我們只需要將

<rule ref="rulesets/java/basic.xml" />

這段改為

<rule ref="rulesets/java/basic.xml">

<exclude name="ForLoopShouldBeWhileLoop" />

</rule>

是不是超級簡單哈~~~~主要是exclude關鍵字在起作用哦~~

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 程序員小新人學習 的精彩文章:

XML DOM 節點類型
Redis 數據備份與恢復

TAG:程序員小新人學習 |