Merge branch 'master' into api-ruleset-compatibility
This commit is contained in:
@ -1,25 +1,20 @@
|
||||
# This is your sidebar TOC. The sidebar code loops through sections here and
|
||||
# provides the appropriate formatting.
|
||||
|
||||
entries:
|
||||
- title: sidebar
|
||||
product: PMD
|
||||
version: "!PMD_VERSION!"
|
||||
version: '!PMD_VERSION!'
|
||||
folders:
|
||||
|
||||
- title:
|
||||
- title: null
|
||||
output: pdf
|
||||
type: frontmatter
|
||||
folderitems:
|
||||
- title:
|
||||
- title: null
|
||||
url: /titlepage
|
||||
output: pdf
|
||||
type: frontmatter
|
||||
- title:
|
||||
- title: null
|
||||
url: /tocpage
|
||||
output: pdf
|
||||
type: frontmatter
|
||||
|
||||
- title: User Documentation
|
||||
output: web, pdf
|
||||
folderitems:
|
||||
@ -27,7 +22,7 @@ entries:
|
||||
url: /index.html
|
||||
output: web, pdf
|
||||
type: homepage
|
||||
- title: "Release Notes"
|
||||
- title: Release Notes
|
||||
url: /pmd_release_notes.html
|
||||
output: web, pdf
|
||||
- title: Getting Started
|
||||
@ -45,6 +40,8 @@ entries:
|
||||
- title: Suppressing
|
||||
url: /pmd_userdocs_suppressing.html
|
||||
output: web, pdf
|
||||
- title: null
|
||||
output: web, pdf
|
||||
subfolders:
|
||||
- title: Tools / Integrations
|
||||
output: web, pdf
|
||||
@ -58,7 +55,6 @@ entries:
|
||||
- title: Other Tools / Integrations
|
||||
output: web, pdf
|
||||
url: /pmd_userdocs_tools.html
|
||||
|
||||
- title: FAQ
|
||||
url: /pmd_userdocs_faq.html
|
||||
output: web, pdf
|
||||
@ -89,36 +85,195 @@ entries:
|
||||
- title: Rule Reference
|
||||
output: web, pdf
|
||||
folderitems:
|
||||
- title: Apex Rules
|
||||
url: /pmd_rules_apex.html
|
||||
- title: null
|
||||
output: web, pdf
|
||||
- title: Java Rules
|
||||
url: /pmd_rules_java.html
|
||||
subfolders:
|
||||
- title: Apex Rules
|
||||
output: web, pdf
|
||||
subfolderitems:
|
||||
- title: Index
|
||||
output: web, pdf
|
||||
url: /pmd_rules_apex.html
|
||||
- title: Best Practices
|
||||
output: web, pdf
|
||||
url: /pmd_rules_apex_bestpractices.html
|
||||
- title: Codestyle
|
||||
output: web, pdf
|
||||
url: /pmd_rules_apex_codestyle.html
|
||||
- title: Design
|
||||
output: web, pdf
|
||||
url: /pmd_rules_apex_design.html
|
||||
- title: Error Prone
|
||||
output: web, pdf
|
||||
url: /pmd_rules_apex_errorprone.html
|
||||
- title: Performance
|
||||
output: web, pdf
|
||||
url: /pmd_rules_apex_performance.html
|
||||
- title: Security
|
||||
output: web, pdf
|
||||
url: /pmd_rules_apex_security.html
|
||||
- title: null
|
||||
output: web, pdf
|
||||
- title: JavaScript Rules
|
||||
url: /pmd_rules_ecmascript.html
|
||||
subfolders:
|
||||
- title: Ecmascript Rules
|
||||
output: web, pdf
|
||||
subfolderitems:
|
||||
- title: Index
|
||||
output: web, pdf
|
||||
url: /pmd_rules_ecmascript.html
|
||||
- title: Best Practices
|
||||
output: web, pdf
|
||||
url: /pmd_rules_ecmascript_bestpractices.html
|
||||
- title: Code Style
|
||||
output: web, pdf
|
||||
url: /pmd_rules_ecmascript_codestyle.html
|
||||
- title: Error Prone
|
||||
output: web, pdf
|
||||
url: /pmd_rules_ecmascript_errorprone.html
|
||||
- title: null
|
||||
output: web, pdf
|
||||
- title: JSP Rules
|
||||
url: /pmd_rules_jsp.html
|
||||
subfolders:
|
||||
- title: Java Rules
|
||||
output: web, pdf
|
||||
subfolderitems:
|
||||
- title: Index
|
||||
output: web, pdf
|
||||
url: /pmd_rules_java.html
|
||||
- title: Best Practices
|
||||
output: web, pdf
|
||||
url: /pmd_rules_java_bestpractices.html
|
||||
- title: Code Style
|
||||
output: web, pdf
|
||||
url: /pmd_rules_java_codestyle.html
|
||||
- title: Design
|
||||
output: web, pdf
|
||||
url: /pmd_rules_java_design.html
|
||||
- title: Documentation
|
||||
output: web, pdf
|
||||
url: /pmd_rules_java_documentation.html
|
||||
- title: Error Prone
|
||||
output: web, pdf
|
||||
url: /pmd_rules_java_errorprone.html
|
||||
- title: Multithreading
|
||||
output: web, pdf
|
||||
url: /pmd_rules_java_multithreading.html
|
||||
- title: Performance
|
||||
output: web, pdf
|
||||
url: /pmd_rules_java_performance.html
|
||||
- title: null
|
||||
output: web, pdf
|
||||
- title: PLSQL Rules
|
||||
url: /pmd_rules_plsql.html
|
||||
subfolders:
|
||||
- title: Java Server Pages Rules
|
||||
output: web, pdf
|
||||
subfolderitems:
|
||||
- title: Index
|
||||
output: web, pdf
|
||||
url: /pmd_rules_jsp.html
|
||||
- title: Best Practices
|
||||
output: web, pdf
|
||||
url: /pmd_rules_jsp_bestpractices.html
|
||||
- title: Codestyle
|
||||
output: web, pdf
|
||||
url: /pmd_rules_jsp_codestyle.html
|
||||
- title: Design
|
||||
output: web, pdf
|
||||
url: /pmd_rules_jsp_design.html
|
||||
- title: Error Prone
|
||||
output: web, pdf
|
||||
url: /pmd_rules_jsp_errorprone.html
|
||||
- title: Security
|
||||
output: web, pdf
|
||||
url: /pmd_rules_jsp_security.html
|
||||
- title: null
|
||||
output: web, pdf
|
||||
- title: Maven POM Rules
|
||||
url: /pmd_rules_pom.html
|
||||
subfolders:
|
||||
- title: Maven POM Rules
|
||||
output: web, pdf
|
||||
subfolderitems:
|
||||
- title: Index
|
||||
output: web, pdf
|
||||
url: /pmd_rules_pom.html
|
||||
- title: Errorprone
|
||||
output: web, pdf
|
||||
url: /pmd_rules_pom_errorprone.html
|
||||
- title: null
|
||||
output: web, pdf
|
||||
- title: VisualForce Rules
|
||||
url: /pmd_rules_vf.html
|
||||
subfolders:
|
||||
- title: PLSQL Rules
|
||||
output: web, pdf
|
||||
subfolderitems:
|
||||
- title: Index
|
||||
output: web, pdf
|
||||
url: /pmd_rules_plsql.html
|
||||
- title: Best Practices
|
||||
output: web, pdf
|
||||
url: /pmd_rules_plsql_bestpractices.html
|
||||
- title: Codestyle
|
||||
output: web, pdf
|
||||
url: /pmd_rules_plsql_codestyle.html
|
||||
- title: Design
|
||||
output: web, pdf
|
||||
url: /pmd_rules_plsql_design.html
|
||||
- title: Error Prone
|
||||
output: web, pdf
|
||||
url: /pmd_rules_plsql_errorprone.html
|
||||
- title: null
|
||||
output: web, pdf
|
||||
- title: Apache Velocity Rules
|
||||
url: /pmd_rules_vm.html
|
||||
subfolders:
|
||||
- title: Salesforce VisualForce Rules
|
||||
output: web, pdf
|
||||
subfolderitems:
|
||||
- title: Index
|
||||
output: web, pdf
|
||||
url: /pmd_rules_vf.html
|
||||
- title: Security
|
||||
output: web, pdf
|
||||
url: /pmd_rules_vf_security.html
|
||||
- title: null
|
||||
output: web, pdf
|
||||
- title: XML Rules
|
||||
url: /pmd_rules_xml.html
|
||||
subfolders:
|
||||
- title: VM Rules
|
||||
output: web, pdf
|
||||
subfolderitems:
|
||||
- title: Index
|
||||
output: web, pdf
|
||||
url: /pmd_rules_vm.html
|
||||
- title: Best Practices
|
||||
output: web, pdf
|
||||
url: /pmd_rules_vm_bestpractices.html
|
||||
- title: Design
|
||||
output: web, pdf
|
||||
url: /pmd_rules_vm_design.html
|
||||
- title: Errorprone
|
||||
output: web, pdf
|
||||
url: /pmd_rules_vm_errorprone.html
|
||||
- title: null
|
||||
output: web, pdf
|
||||
- title: XSL Rules
|
||||
url: /pmd_rules_xsl.html
|
||||
subfolders:
|
||||
- title: XML Rules
|
||||
output: web, pdf
|
||||
subfolderitems:
|
||||
- title: Index
|
||||
output: web, pdf
|
||||
url: /pmd_rules_xml.html
|
||||
- title: Errorprone
|
||||
output: web, pdf
|
||||
url: /pmd_rules_xml_errorprone.html
|
||||
- title: null
|
||||
output: web, pdf
|
||||
subfolders:
|
||||
- title: XSL Rules
|
||||
output: web, pdf
|
||||
subfolderitems:
|
||||
- title: Index
|
||||
output: web, pdf
|
||||
url: /pmd_rules_xsl.html
|
||||
- title: Codestyle
|
||||
output: web, pdf
|
||||
url: /pmd_rules_xsl_codestyle.html
|
||||
- title: Performance
|
||||
output: web, pdf
|
||||
url: /pmd_rules_xsl_performance.html
|
||||
- title: Language Specific Documentation
|
||||
output: web, pdf
|
||||
folderitems:
|
||||
@ -194,3 +349,4 @@ entries:
|
||||
- title: Adding metrics support to a language
|
||||
url: /pmd_devdocs_adding_metrics_support_to_language.html
|
||||
output: web, pdf
|
||||
|
||||
|
@ -14,33 +14,44 @@
|
||||
<ul>
|
||||
{% for folderitem in folder.folderitems %}
|
||||
{% if folderitem.output contains "web" %}
|
||||
{% if folderitem.external_url %}
|
||||
<li><a href="{{folderitem.external_url}}" target="_blank">{{folderitem.title}}</a></li>
|
||||
{% elsif page.url == folderitem.url or page.sidebaractiveurl == folderitem.url %}
|
||||
<li class="active"><a href="{{folderitem.url | remove: "/"}}">{{folderitem.title}}</a></li>
|
||||
|
||||
{% unless folderitem.subfolders %}
|
||||
|
||||
{% if folderitem.external_url %}
|
||||
<li><a href="{{folderitem.external_url}}" target="_blank">{{folderitem.title}}</a></li>
|
||||
{% elsif folderitem.url and page.url == folderitem.url or page.sidebaractiveurl == folderitem.url %}
|
||||
<li class="active"><a href="{{folderitem.url | remove: "/"}}">{{folderitem.title}}</a></li>
|
||||
{% elsif folderitem.url %}
|
||||
<li><a href="{{folderitem.url | remove: "/"}}">{{folderitem.title}}</a></li>
|
||||
{% else %}
|
||||
<li><a href="#">{{folderitem.title}}</a></li>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<li><a href="{{folderitem.url | remove: "/"}}">{{folderitem.title}}</a></li>
|
||||
{% endif %}
|
||||
{% for subfolders in folderitem.subfolders %}
|
||||
{% if subfolders.output contains "web" %}
|
||||
<li class="subfolders">
|
||||
<a href="#">{{ subfolders.title }}</a>
|
||||
<ul>
|
||||
{% for subfolderitem in subfolders.subfolderitems %}
|
||||
{% if subfolderitem.output contains "web" %}
|
||||
{% if subfolderitem.external_url %}
|
||||
<li><a href="{{subfolderitem.external_url}}" target="_blank">{{subfolderitem.title}}</a></li>
|
||||
{% elsif page.url == subfolderitem.url %}
|
||||
<li class="active"><a href="{{subfolderitem.url | remove: "/"}}">{{subfolderitem.title}}</a></li>
|
||||
{% else %}
|
||||
<li><a href="{{subfolderitem.url | remove: "/"}}">{{subfolderitem.title}}</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% for subfolders in folderitem.subfolders %}
|
||||
{% if subfolders.output contains "web" %}
|
||||
<li class="subfolders">
|
||||
<a href="#">{{ subfolders.title }}</a>
|
||||
<ul>
|
||||
{% for subfolderitem in subfolders.subfolderitems %}
|
||||
{% if subfolderitem.output contains "web" %}
|
||||
{% if subfolderitem.external_url %}
|
||||
<li><a href="{{subfolderitem.external_url}}" target="_blank">{{subfolderitem.title}}</a></li>
|
||||
{% elsif page.url == subfolderitem.url %}
|
||||
<li class="active"><a href="{{subfolderitem.url | remove: "/"}}">{{subfolderitem.title}}</a></li>
|
||||
{% else %}
|
||||
<li><a href="{{subfolderitem.url | remove: "/"}}">{{subfolderitem.title}}</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% endunless %}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
@ -75,7 +75,7 @@ folder: pmd/devdocs
|
||||
* All other rules for your language should extend this class. The purpose of this class is to implement visit methods for all AST types to simply delegate to default behavior. This is useful because most rules care only about specific AST nodes, but PMD needs to know what to do with each node - so this just lets you use default behavior for nodes you don’t care about.
|
||||
|
||||
## 13. Create rules
|
||||
* Rules are ceated by extending the abstract rule class created in step 12 *(see `EmptyForeachStmtRule` for example)*
|
||||
* Rules are created by extending the abstract rule class created in step 12 *(see `EmptyForeachStmtRule` for example)*
|
||||
* Creating rules is already pretty well documented in PMD - and it’s no different for a new language, except you may have different AST nodes.
|
||||
|
||||
## 14. Test the rules
|
||||
|
@ -6,3 +6,5 @@ folder: pmd/devdocs
|
||||
---
|
||||
|
||||
PMD high-level building blocks
|
||||
|
||||
TODO
|
||||
|
@ -4,3 +4,7 @@ sidebar: pmd_sidebar
|
||||
permalink: pmd_devdocs_codestyle.html
|
||||
folder: pmd/devdocs
|
||||
---
|
||||
|
||||
TODO
|
||||
|
||||
* Checkstyle
|
||||
|
@ -2,7 +2,7 @@
|
||||
title: PMD Making Rulesets
|
||||
tags: [customizing]
|
||||
summary: Making Custom Rulesets for PMD
|
||||
last_updated: July 3, 2016
|
||||
last_updated: November 2017
|
||||
permalink: pmd_devdocs_making_rulesets.html
|
||||
author: Tom Copeland <tomcopeland@users.sourceforge.net>
|
||||
---
|
||||
@ -18,12 +18,12 @@ Use one of the current rulesets as an example. Copy and paste it into your new f
|
||||
```xml
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="Custom ruleset"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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>
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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>
|
||||
</ruleset>
|
||||
````
|
||||
|
||||
@ -42,31 +42,27 @@ After you add these references it’ll look something like this:
|
||||
This ruleset checks my code for bad stuff
|
||||
</description>
|
||||
|
||||
<!-- We'll use the entire 'strings' ruleset -->
|
||||
<rule ref="rulesets/java/strings.xml"/>
|
||||
|
||||
<!-- Here's some rules we'll specify one at a time -->
|
||||
<rule ref="rulesets/java/unusedcode.xml/UnusedLocalVariable"/>
|
||||
<rule ref="rulesets/java/unusedcode.xml/UnusedPrivateField"/>
|
||||
<rule ref="rulesets/java/imports.xml/DuplicateImports"/>
|
||||
<rule ref="rulesets/java/basic.xml/UnnecessaryConversionTemporary"/>
|
||||
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable"/>
|
||||
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
|
||||
<rule ref="category/java/codestyle.xml/DuplicateImports"/>
|
||||
<rule ref="category/java/errorprone.xml/UnnecessaryConversionTemporary"/>
|
||||
|
||||
<!-- We want to customize this rule a bit, change the message and raise the priority -->
|
||||
<rule
|
||||
ref="rulesets/java/basic.xml/EmptyCatchBlock"
|
||||
<rule ref="category/java/errorprone.xml/EmptyCatchBlock"
|
||||
message="Must handle exceptions">
|
||||
<priority>2</priority>
|
||||
</rule>
|
||||
|
||||
<!-- Now we'll customize a rule's property value -->
|
||||
<rule ref="rulesets/java/codesize.xml/CyclomaticComplexity">
|
||||
<rule ref="category/java/design.xml/CyclomaticComplexity">
|
||||
<properties>
|
||||
<property name="reportLevel" value="5"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- We want everything from braces.xml except WhileLoopsMustUseBraces -->
|
||||
<rule ref="rulesets/java/braces.xml">
|
||||
<!-- We want everything from category Code Style except WhileLoopsMustUseBraces -->
|
||||
<rule ref="category/java/codestyle.xml">
|
||||
<exclude name="WhileLoopsMustUseBraces"/>
|
||||
</rule>
|
||||
</ruleset>
|
||||
@ -76,16 +72,16 @@ After you add these references it’ll look something like this:
|
||||
|
||||
## Excluding rules from a ruleset
|
||||
|
||||
You can also make a custom ruleset that excludes rules, like this:
|
||||
You can also make a custom ruleset by referencing a complete category and exclude certain rules, like this:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="mybraces"
|
||||
<ruleset name="myruleset"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
|
||||
<description>Just the braces rules I like</description>
|
||||
<rule ref="rulesets/java/braces.xml">
|
||||
<description>All codestyle rules, but with just the braces rules I like</description>
|
||||
<rule ref="category/java/codestyle.xml">
|
||||
<exclude name="WhileLoopsMustUseBraces"/>
|
||||
<exclude name="IfElseStmtsMustUseBraces"/>
|
||||
</rule>
|
||||
@ -123,9 +119,9 @@ You can specify the full path to your custom ruleset name alongside of the built
|
||||
</pmd>
|
||||
```
|
||||
|
||||
## To see it in your IDE, add it to rulesets/rulesets.properties
|
||||
## To see it in your IDE
|
||||
|
||||
At least, that’s the way some of the IDE plugins do it. Some have other ways of adding custom rulesets.
|
||||
You'll need to point the IDE plugin to the location of your custom ruleset.
|
||||
|
||||
## Send us feedback
|
||||
|
||||
|
@ -51,8 +51,8 @@ See [Test Framework](pmd_devdocs_testing.html) for the general documentation
|
||||
|
||||
### … for a rule I want to submit (in a patch)
|
||||
|
||||
Figure out the ruleset to which you want to the rule. Then add your rule to the appropriate test class for
|
||||
the ruleset and add the XML test data in the correct xml subpackage.
|
||||
Figure out the category to which you want to the rule. Then add your rule to the appropriate test class for
|
||||
the category and add the XML test data in the correct xml subpackage.
|
||||
|
||||
### … for something too specific, that I won’t be able to submit
|
||||
|
||||
|
@ -41,37 +41,37 @@ The XML file is a test resource, so it is searched in the tree under `src/test/r
|
||||
The sub package `xml` of the test class's package should contain a file with the same name as the rule's name
|
||||
which is under test.
|
||||
|
||||
For example, to test the "Java Basic Ruleset", the fully qualified test class is:
|
||||
For example, to test the "Java Error Prone Category", the fully qualified test class is:
|
||||
|
||||
net.sourceforge.pmd.lang.java.rule.basic.BasicRulesTest
|
||||
net.sourceforge.pmd.lang.java.rule.errorprone.ErrorProneRulesTest
|
||||
|
||||
The test code for the rule "AvoidBranchingStatementAsLastInLoop" can be found in the file:
|
||||
|
||||
src/test/resources/net/sourceforge/pmd/lang/java/rule/basic/xml/AvoidBranchingStatementAsLastInLoop.xml
|
||||
src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidBranchingStatementAsLastInLoop.xml
|
||||
|
||||
In general, the class name and file name pattern for the test class and data is this:
|
||||
|
||||
net.sourceforge.pmd.lang.<Language Terse Name>.rule.<Ruleset Name>.<Ruleset Name>RulesTest
|
||||
src/test/resources/net/sourceforge/pmd/lang/<Language Terse Name>/rule/<Ruleset Name>/xml/<Rule Name>.xml
|
||||
net.sourceforge.pmd.lang.<Language Terse Name>.rule.<Category Name>.<Category Name>RulesTest
|
||||
src/test/resources/net/sourceforge/pmd/lang/<Language Terse Name>/rule/<Category Name>/xml/<Rule Name>.xml
|
||||
|
||||
{%include tip.html content="This convention allows you to quickly find the test cases for a given rule:
|
||||
Just search in the project for a file `<RuleName>.xml`. Looking at the path of the file, you can figure
|
||||
out the ruleset name. Searching for a class `<Ruleset Name>RulesTest` gives you the test class." %}
|
||||
out the category. Searching for a class `<Category Name>RulesTest` gives you the test class." %}
|
||||
|
||||
## Simple example
|
||||
|
||||
### Test Class: BasicRulesTest
|
||||
### Test Class: ErrorProneRulesTest
|
||||
|
||||
This is a stripped down example for the Java Basic Ruleset:
|
||||
This is a stripped down example for the Java Error Prone Category:
|
||||
|
||||
``` java
|
||||
package net.sourceforge.pmd.lang.java.rule.basic;
|
||||
package net.sourceforge.pmd.lang.java.rule.errorprone;
|
||||
|
||||
import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
|
||||
public class BasicRulesTest extends SimpleAggregatorTst {
|
||||
public class ErrorProneRulesTest extends SimpleAggregatorTst {
|
||||
|
||||
private static final String RULESET = "java-basic";
|
||||
private static final String RULESET = "category/java/errorprone.xml";
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
@ -84,9 +84,6 @@ public class BasicRulesTest extends SimpleAggregatorTst {
|
||||
This test class overrides the method `setUp` in order to register test cases for the two rules. If there
|
||||
are more rules, just add additional `addRule(...)` calls.
|
||||
|
||||
{%include note.html content="The `RULESET` constant points to `java-basic` which is just a shortcut
|
||||
for `rulesets/java/basic.xml`. " %}
|
||||
|
||||
{%include note.html content="You can also add additionally standard JUnit test methods annotated with `@Test` to
|
||||
this test class." %}
|
||||
|
||||
|
@ -72,7 +72,7 @@ CompilationUnit
|
||||
|
||||
You can generate this yourself by:
|
||||
|
||||
* Run the batch file bin/designer.bat
|
||||
* Run the batch file `bin/designer.bat`
|
||||
* Paste the code into the left text area and click the “Go” button
|
||||
* Note that there’s another panel and a textfield to test out XPath expressions; more on that later.
|
||||
* Here’s a screenshot: {% include image.html file="devdocs/designer_screenshot.png" alt="Designer Screenshot" %}
|
||||
@ -154,7 +154,7 @@ We stuck a `println()` in there for now so we can see when our rule gets hit.
|
||||
|
||||
## Put the WhileLoopsMustUseBracesRule rule in a ruleset file
|
||||
|
||||
Now our rule is written - at least, the shell of it is - and now we need to tell PMD about it. We need to add it to a ruleset XML file. Look at `pmd-java/src/main/resources/rulesets/java/basic.xml`; it’s got lots of rule definitions in it. Copy and paste one of these rules into a new ruleset - call it `mycustomrules.xml` or something. Then fill in the elements and attributes:
|
||||
Now our rule is written - at least, the shell of it is - and now we need to tell PMD about it. We need to add it to a ruleset XML file. Look at `pmd-java/src/main/resources/category/java/bestpractices.xml`; it’s got lots of rule definitions in it. Copy and paste one of these rules into a new ruleset - call it `mycustomrules.xml` or something. Then fill in the elements and attributes:
|
||||
|
||||
* name - WhileLoopsMustUseBracesRule
|
||||
* message - Use braces for while loops
|
||||
|
@ -3,22 +3,19 @@ title: Apex Rules
|
||||
permalink: pmd_rules_apex.html
|
||||
folder: pmd/rules
|
||||
---
|
||||
List of rulesets and rules contained in each ruleset.
|
||||
|
||||
* [Best Practices](pmd_rules_apex_bestpractices.html): Rules which enforce generally accepted best practices.
|
||||
* [Codestyle](pmd_rules_apex_codestyle.html): Rules which enforce a specific coding style.
|
||||
* [Design](pmd_rules_apex_design.html): Rules that help you discover design issues.
|
||||
* [Error Prone](pmd_rules_apex_errorprone.html): Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
|
||||
* [Performance](pmd_rules_apex_performance.html): Rules that flag suboptimal code.
|
||||
* [Security](pmd_rules_apex_security.html): Rules that flag potential security flaws.
|
||||
|
||||
## Best Practices
|
||||
|
||||
{% include callout.html content="Rules which enforce generally accepted best practices." %}
|
||||
|
||||
* [ApexUnitTestClassShouldHaveAsserts](pmd_rules_apex_bestpractices.html#apexunittestclassshouldhaveasserts): Apex unit tests should include at least one assertion. This makes the tests more robust, and usi...
|
||||
* [ApexUnitTestShouldNotUseSeeAllDataTrue](pmd_rules_apex_bestpractices.html#apexunittestshouldnotuseseealldatatrue): Apex unit tests should not use @isTest(seeAllData=true) because it opens up the existing database...
|
||||
* [AvoidGlobalModifier](pmd_rules_apex_bestpractices.html#avoidglobalmodifier): Global classes should be avoided (especially in managed packages) as they can never be deleted or...
|
||||
* [AvoidLogicInTrigger](pmd_rules_apex_bestpractices.html#avoidlogicintrigger): As triggers do not allow methods like regular classes they are less flexible and suited to apply ...
|
||||
|
||||
## Codestyle
|
||||
|
||||
{% include callout.html content="Rules which enforce a specific coding style." %}
|
||||
|
||||
* [ClassNamingConventions](pmd_rules_apex_codestyle.html#classnamingconventions): Class names should always begin with an upper case character.
|
||||
* [ForLoopsMustUseBraces](pmd_rules_apex_codestyle.html#forloopsmustusebraces): Avoid using 'for' statements without using surrounding braces. If the code formatting orindentati...
|
||||
* [IfElseStmtsMustUseBraces](pmd_rules_apex_codestyle.html#ifelsestmtsmustusebraces): Avoid using if..else statements without using surrounding braces. If the code formattingor indent...
|
||||
@ -28,6 +25,9 @@ List of rulesets and rules contained in each ruleset.
|
||||
* [WhileLoopsMustUseBraces](pmd_rules_apex_codestyle.html#whileloopsmustusebraces): Avoid using 'while' statements without using braces to surround the code block. If the codeformat...
|
||||
|
||||
## Design
|
||||
|
||||
{% include callout.html content="Rules that help you discover design issues." %}
|
||||
|
||||
* [AvoidDeeplyNestedIfStmts](pmd_rules_apex_design.html#avoiddeeplynestedifstmts): Avoid creating deeply nested if-then statements since they are harder to read and error-prone to ...
|
||||
* [CyclomaticComplexity](pmd_rules_apex_design.html#cyclomaticcomplexity): The complexity of methods directly affects maintenance costs and readability. Concentrating too m...
|
||||
* [ExcessiveClassLength](pmd_rules_apex_design.html#excessiveclasslength): Excessive class file lengths are usually indications that the class may be burdened with excessiv...
|
||||
@ -40,6 +40,9 @@ List of rulesets and rules contained in each ruleset.
|
||||
* [TooManyFields](pmd_rules_apex_design.html#toomanyfields): Classes that have too many fields can become unwieldy and could be redesigned to have fewer field...
|
||||
|
||||
## Error Prone
|
||||
|
||||
{% include callout.html content="Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors." %}
|
||||
|
||||
* [AvoidDirectAccessTriggerMap](pmd_rules_apex_errorprone.html#avoiddirectaccesstriggermap): Avoid directly accessing Trigger.old and Trigger.new as it can lead to a bug. Triggers should be ...
|
||||
* [AvoidHardcodingId](pmd_rules_apex_errorprone.html#avoidhardcodingid): When deploying Apex code between sandbox and production environments, or installing Force.com App...
|
||||
* [EmptyCatchBlock](pmd_rules_apex_errorprone.html#emptycatchblock): Empty Catch Block finds instances where an exception is caught, but nothing is done. In most cir...
|
||||
@ -50,11 +53,17 @@ List of rulesets and rules contained in each ruleset.
|
||||
* [MethodWithSameNameAsEnclosingClass](pmd_rules_apex_errorprone.html#methodwithsamenameasenclosingclass): Non-constructor methods should not have the same name as the enclosing class.
|
||||
|
||||
## Performance
|
||||
|
||||
{% include callout.html content="Rules that flag suboptimal code." %}
|
||||
|
||||
* [AvoidDmlStatementsInLoops](pmd_rules_apex_performance.html#avoiddmlstatementsinloops): Avoid DML statements inside loops to avoid hitting the DML governor limit. Instead, try to batch ...
|
||||
* [AvoidSoqlInLoops](pmd_rules_apex_performance.html#avoidsoqlinloops): New objects created within loops should be checked to see if they can created outside them and re...
|
||||
* [AvoidSoslInLoops](pmd_rules_apex_performance.html#avoidsoslinloops): Sosl calls within loops can cause governor limit exceptions.
|
||||
|
||||
## Security
|
||||
|
||||
{% include callout.html content="Rules that flag potential security flaws." %}
|
||||
|
||||
* [ApexBadCrypto](pmd_rules_apex_security.html#apexbadcrypto): The rule makes sure you are using randomly generated IVs and keys for 'Crypto' calls.Hard-wiring ...
|
||||
* [ApexCRUDViolation](pmd_rules_apex_security.html#apexcrudviolation): The rule validates you are checking for access permissions before a SOQL/SOSL/DML operation.Since...
|
||||
* [ApexCSRF](pmd_rules_apex_security.html#apexcsrf): Check to avoid making DML operations in Apex class constructor/init method. This preventsmodifica...
|
||||
@ -67,3 +76,78 @@ List of rulesets and rules contained in each ruleset.
|
||||
* [ApexXSSFromEscapeFalse](pmd_rules_apex_security.html#apexxssfromescapefalse): Reports on calls to 'addError' with disabled escaping. The message passed to 'addError'will be di...
|
||||
* [ApexXSSFromURLParam](pmd_rules_apex_security.html#apexxssfromurlparam): Makes sure that all values obtained from URL parameters are properly escaped / sanitizedto avoid ...
|
||||
|
||||
## Additional rulesets
|
||||
|
||||
* ApexUnit (`rulesets/apex/apexunit.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[ApexUnitTestClassShouldHaveAsserts](pmd_rules_apex_bestpractices.html#apexunittestclassshouldhaveasserts), [ApexUnitTestShouldNotUseSeeAllDataTrue](pmd_rules_apex_bestpractices.html#apexunittestshouldnotuseseealldatatrue)
|
||||
|
||||
* Braces (`rulesets/apex/braces.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[ForLoopsMustUseBraces](pmd_rules_apex_codestyle.html#forloopsmustusebraces), [IfElseStmtsMustUseBraces](pmd_rules_apex_codestyle.html#ifelsestmtsmustusebraces), [IfStmtsMustUseBraces](pmd_rules_apex_codestyle.html#ifstmtsmustusebraces), [WhileLoopsMustUseBraces](pmd_rules_apex_codestyle.html#whileloopsmustusebraces)
|
||||
|
||||
* Complexity (`rulesets/apex/complexity.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[AvoidDeeplyNestedIfStmts](pmd_rules_apex_design.html#avoiddeeplynestedifstmts), [ExcessiveClassLength](pmd_rules_apex_design.html#excessiveclasslength), [ExcessiveParameterList](pmd_rules_apex_design.html#excessiveparameterlist), [ExcessivePublicCount](pmd_rules_apex_design.html#excessivepubliccount), [NcssConstructorCount](pmd_rules_apex_design.html#ncssconstructorcount), [NcssMethodCount](pmd_rules_apex_design.html#ncssmethodcount), [NcssTypeCount](pmd_rules_apex_design.html#ncsstypecount), [StdCyclomaticComplexity](pmd_rules_apex_design.html#stdcyclomaticcomplexity), [TooManyFields](pmd_rules_apex_design.html#toomanyfields)
|
||||
|
||||
* Default ruleset used by the CodeClimate Engine for Salesforce.com Apex (`rulesets/apex/ruleset.xml`):
|
||||
|
||||
Default ruleset used by the Code Climate Engine for Salesforce.com Apex
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[ApexBadCrypto](pmd_rules_apex_security.html#apexbadcrypto), [ApexCRUDViolation](pmd_rules_apex_security.html#apexcrudviolation), [ApexCSRF](pmd_rules_apex_security.html#apexcsrf), [ApexDangerousMethods](pmd_rules_apex_security.html#apexdangerousmethods), [ApexInsecureEndpoint](pmd_rules_apex_security.html#apexinsecureendpoint), [ApexOpenRedirect](pmd_rules_apex_security.html#apexopenredirect), [ApexSharingViolations](pmd_rules_apex_security.html#apexsharingviolations), [ApexSOQLInjection](pmd_rules_apex_security.html#apexsoqlinjection), [ApexSuggestUsingNamedCred](pmd_rules_apex_security.html#apexsuggestusingnamedcred), [ApexUnitTestClassShouldHaveAsserts](pmd_rules_apex_bestpractices.html#apexunittestclassshouldhaveasserts), [ApexUnitTestShouldNotUseSeeAllDataTrue](pmd_rules_apex_bestpractices.html#apexunittestshouldnotuseseealldatatrue), [ApexXSSFromEscapeFalse](pmd_rules_apex_security.html#apexxssfromescapefalse), [ApexXSSFromURLParam](pmd_rules_apex_security.html#apexxssfromurlparam), [AvoidDeeplyNestedIfStmts](pmd_rules_apex_design.html#avoiddeeplynestedifstmts), [AvoidDirectAccessTriggerMap](pmd_rules_apex_errorprone.html#avoiddirectaccesstriggermap), [AvoidDmlStatementsInLoops](pmd_rules_apex_performance.html#avoiddmlstatementsinloops), [AvoidGlobalModifier](pmd_rules_apex_bestpractices.html#avoidglobalmodifier), [AvoidHardcodingId](pmd_rules_apex_errorprone.html#avoidhardcodingid), [AvoidLogicInTrigger](pmd_rules_apex_bestpractices.html#avoidlogicintrigger), [AvoidSoqlInLoops](pmd_rules_apex_performance.html#avoidsoqlinloops), [AvoidSoslInLoops](pmd_rules_apex_performance.html#avoidsoslinloops), [ClassNamingConventions](pmd_rules_apex_codestyle.html#classnamingconventions), [CyclomaticComplexity](pmd_rules_apex_design.html#cyclomaticcomplexity), [EmptyCatchBlock](pmd_rules_apex_errorprone.html#emptycatchblock), [EmptyIfStmt](pmd_rules_apex_errorprone.html#emptyifstmt), [EmptyStatementBlock](pmd_rules_apex_errorprone.html#emptystatementblock), [EmptyTryOrFinallyBlock](pmd_rules_apex_errorprone.html#emptytryorfinallyblock), [EmptyWhileStmt](pmd_rules_apex_errorprone.html#emptywhilestmt), [ExcessiveClassLength](pmd_rules_apex_design.html#excessiveclasslength), [ExcessiveParameterList](pmd_rules_apex_design.html#excessiveparameterlist), [ExcessivePublicCount](pmd_rules_apex_design.html#excessivepubliccount), [ForLoopsMustUseBraces](pmd_rules_apex_codestyle.html#forloopsmustusebraces), [IfElseStmtsMustUseBraces](pmd_rules_apex_codestyle.html#ifelsestmtsmustusebraces), [IfStmtsMustUseBraces](pmd_rules_apex_codestyle.html#ifstmtsmustusebraces), [MethodNamingConventions](pmd_rules_apex_codestyle.html#methodnamingconventions), [MethodWithSameNameAsEnclosingClass](pmd_rules_apex_errorprone.html#methodwithsamenameasenclosingclass), [NcssConstructorCount](pmd_rules_apex_design.html#ncssconstructorcount), [NcssMethodCount](pmd_rules_apex_design.html#ncssmethodcount), [NcssTypeCount](pmd_rules_apex_design.html#ncsstypecount), [StdCyclomaticComplexity](pmd_rules_apex_design.html#stdcyclomaticcomplexity), [TooManyFields](pmd_rules_apex_design.html#toomanyfields), [VariableNamingConventions](pmd_rules_apex_codestyle.html#variablenamingconventions), [WhileLoopsMustUseBraces](pmd_rules_apex_codestyle.html#whileloopsmustusebraces)
|
||||
|
||||
* Empty Code (`rulesets/apex/empty.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[EmptyCatchBlock](pmd_rules_apex_errorprone.html#emptycatchblock), [EmptyIfStmt](pmd_rules_apex_errorprone.html#emptyifstmt), [EmptyStatementBlock](pmd_rules_apex_errorprone.html#emptystatementblock), [EmptyTryOrFinallyBlock](pmd_rules_apex_errorprone.html#emptytryorfinallyblock), [EmptyWhileStmt](pmd_rules_apex_errorprone.html#emptywhilestmt)
|
||||
|
||||
* Metrics temporary ruleset (`rulesets/apex/metrics.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[CyclomaticComplexity](pmd_rules_apex_design.html#cyclomaticcomplexity)
|
||||
|
||||
* Performance (`rulesets/apex/performance.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[AvoidDmlStatementsInLoops](pmd_rules_apex_performance.html#avoiddmlstatementsinloops), [AvoidSoqlInLoops](pmd_rules_apex_performance.html#avoidsoqlinloops), [AvoidSoslInLoops](pmd_rules_apex_performance.html#avoidsoslinloops)
|
||||
|
||||
* Security (`rulesets/apex/security.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[ApexBadCrypto](pmd_rules_apex_security.html#apexbadcrypto), [ApexCRUDViolation](pmd_rules_apex_security.html#apexcrudviolation), [ApexCSRF](pmd_rules_apex_security.html#apexcsrf), [ApexDangerousMethods](pmd_rules_apex_security.html#apexdangerousmethods), [ApexInsecureEndpoint](pmd_rules_apex_security.html#apexinsecureendpoint), [ApexOpenRedirect](pmd_rules_apex_security.html#apexopenredirect), [ApexSharingViolations](pmd_rules_apex_security.html#apexsharingviolations), [ApexSOQLInjection](pmd_rules_apex_security.html#apexsoqlinjection), [ApexSuggestUsingNamedCred](pmd_rules_apex_security.html#apexsuggestusingnamedcred), [ApexXSSFromEscapeFalse](pmd_rules_apex_security.html#apexxssfromescapefalse), [ApexXSSFromURLParam](pmd_rules_apex_security.html#apexxssfromurlparam)
|
||||
|
||||
* Style (`rulesets/apex/style.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[AvoidDirectAccessTriggerMap](pmd_rules_apex_errorprone.html#avoiddirectaccesstriggermap), [AvoidGlobalModifier](pmd_rules_apex_bestpractices.html#avoidglobalmodifier), [AvoidHardcodingId](pmd_rules_apex_errorprone.html#avoidhardcodingid), [AvoidLogicInTrigger](pmd_rules_apex_bestpractices.html#avoidlogicintrigger), [ClassNamingConventions](pmd_rules_apex_codestyle.html#classnamingconventions), [MethodNamingConventions](pmd_rules_apex_codestyle.html#methodnamingconventions), [MethodWithSameNameAsEnclosingClass](pmd_rules_apex_errorprone.html#methodwithsamenameasenclosingclass), [VariableNamingConventions](pmd_rules_apex_codestyle.html#variablenamingconventions)
|
||||
|
||||
|
||||
|
@ -3,13 +3,10 @@ title: Ecmascript Rules
|
||||
permalink: pmd_rules_ecmascript.html
|
||||
folder: pmd/rules
|
||||
---
|
||||
List of rulesets and rules contained in each ruleset.
|
||||
|
||||
* [Best Practices](pmd_rules_ecmascript_bestpractices.html): Rules which enforce generally accepted best practices.
|
||||
* [Code Style](pmd_rules_ecmascript_codestyle.html): Rules which enforce a specific coding style.
|
||||
* [Error Prone](pmd_rules_ecmascript_errorprone.html): Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
|
||||
|
||||
## Best Practices
|
||||
|
||||
{% include callout.html content="Rules which enforce generally accepted best practices." %}
|
||||
|
||||
* [AvoidWithStatement](pmd_rules_ecmascript_bestpractices.html#avoidwithstatement): Avoid using with - it's bad news
|
||||
* [ConsistentReturn](pmd_rules_ecmascript_bestpractices.html#consistentreturn): ECMAScript does provide for return types on functions, and therefore there is no solid rule as to...
|
||||
* [GlobalVariable](pmd_rules_ecmascript_bestpractices.html#globalvariable): This rule helps to avoid using accidently global variables by simply missing the "var" declaratio...
|
||||
@ -17,6 +14,9 @@ List of rulesets and rules contained in each ruleset.
|
||||
* [UseBaseWithParseInt](pmd_rules_ecmascript_bestpractices.html#usebasewithparseint): This rule checks for usages of parseInt. While the second parameter is optional and usually defau...
|
||||
|
||||
## Code Style
|
||||
|
||||
{% include callout.html content="Rules which enforce a specific coding style." %}
|
||||
|
||||
* [AssignmentInOperand](pmd_rules_ecmascript_codestyle.html#assignmentinoperand): Avoid assignments in operands; this can make code more complicated and harder to read. This is s...
|
||||
* [ForLoopsMustUseBraces](pmd_rules_ecmascript_codestyle.html#forloopsmustusebraces): Avoid using 'for' statements without using curly braces.
|
||||
* [IfElseStmtsMustUseBraces](pmd_rules_ecmascript_codestyle.html#ifelsestmtsmustusebraces): Avoid using if..else statements without using curly braces.
|
||||
@ -28,7 +28,45 @@ List of rulesets and rules contained in each ruleset.
|
||||
* [WhileLoopsMustUseBraces](pmd_rules_ecmascript_codestyle.html#whileloopsmustusebraces): Avoid using 'while' statements without using curly braces.
|
||||
|
||||
## Error Prone
|
||||
|
||||
{% include callout.html content="Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors." %}
|
||||
|
||||
* [AvoidTrailingComma](pmd_rules_ecmascript_errorprone.html#avoidtrailingcomma): This rule helps improve code portability due to differences in browser treatment of trailing comm...
|
||||
* [EqualComparison](pmd_rules_ecmascript_errorprone.html#equalcomparison): Using == in condition may lead to unexpected results, as the variables are automatically casted t...
|
||||
* [InnaccurateNumericLiteral](pmd_rules_ecmascript_errorprone.html#innaccuratenumericliteral): The numeric literal will have a different value at runtime, which can happen if you provide too m...
|
||||
|
||||
## Additional rulesets
|
||||
|
||||
* Basic Ecmascript (`rulesets/ecmascript/basic.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[AssignmentInOperand](pmd_rules_ecmascript_codestyle.html#assignmentinoperand), [AvoidTrailingComma](pmd_rules_ecmascript_errorprone.html#avoidtrailingcomma), [ConsistentReturn](pmd_rules_ecmascript_bestpractices.html#consistentreturn), [EqualComparison](pmd_rules_ecmascript_errorprone.html#equalcomparison), [GlobalVariable](pmd_rules_ecmascript_bestpractices.html#globalvariable), [InnaccurateNumericLiteral](pmd_rules_ecmascript_errorprone.html#innaccuratenumericliteral), [ScopeForInVariable](pmd_rules_ecmascript_bestpractices.html#scopeforinvariable), [UnreachableCode](pmd_rules_ecmascript_codestyle.html#unreachablecode), [UseBaseWithParseInt](pmd_rules_ecmascript_bestpractices.html#usebasewithparseint)
|
||||
|
||||
* Braces (`rulesets/ecmascript/braces.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[ForLoopsMustUseBraces](pmd_rules_ecmascript_codestyle.html#forloopsmustusebraces), [IfElseStmtsMustUseBraces](pmd_rules_ecmascript_codestyle.html#ifelsestmtsmustusebraces), [IfStmtsMustUseBraces](pmd_rules_ecmascript_codestyle.html#ifstmtsmustusebraces), [WhileLoopsMustUseBraces](pmd_rules_ecmascript_codestyle.html#whileloopsmustusebraces)
|
||||
|
||||
* Controversial Ecmascript (`rulesets/ecmascript/controversial.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[AvoidWithStatement](pmd_rules_ecmascript_bestpractices.html#avoidwithstatement)
|
||||
|
||||
* Unnecessary (`rulesets/ecmascript/unnecessary.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[NoElseReturn](pmd_rules_ecmascript_codestyle.html#noelsereturn), [UnnecessaryBlock](pmd_rules_ecmascript_codestyle.html#unnecessaryblock), [UnnecessaryParentheses](pmd_rules_ecmascript_codestyle.html#unnecessaryparentheses)
|
||||
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -368,57 +368,54 @@ public class Foo {
|
||||
|
||||
## CyclomaticComplexity
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f;">Deprecated</span>
|
||||
|
||||
**Since:** PMD 1.03
|
||||
|
||||
**Priority:** Medium (3)
|
||||
|
||||
Complexity directly affects maintenance costs is determined by the number of decision points in a method
|
||||
plus one for the method entry. The decision points include 'if', 'while', 'for', and 'case labels' calls.
|
||||
The complexity of methods directly affects maintenance costs and readability. Concentrating too much decisional logic
|
||||
in a single method makes its behaviour hard to read and change.
|
||||
|
||||
Cyclomatic complexity assesses the complexity of a method by counting the number of decision points in a method,
|
||||
plus one for the method entry. Decision points are places where the control flow jumps to another place in the
|
||||
program. As such, they include all control flow statements, such as `if`, `while`, `for`, and `case`. For more
|
||||
details on the calculation, see the documentation of the [Cyclo metric](/pmd_java_metrics_index.html#cyclomatic-complexity-cyclo).
|
||||
|
||||
Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote moderate complexity, 8-10 denote
|
||||
high complexity, and 11+ is very high complexity.
|
||||
high complexity, and 11+ is very high complexity. By default, this rule reports methods with a complexity >= 10.
|
||||
Additionnally, classes with many methods of moderate complexity get reported as well once the total of their
|
||||
methods' complexities reaches 80, even if none of the methods was directly reported.
|
||||
|
||||
Reported methods should be broken down into several smaller methods. Reported classes should probably be broken down
|
||||
into subcomponents.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.CyclomaticComplexityRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CyclomaticComplexityRule.java)
|
||||
|
||||
**Example(s):**
|
||||
|
||||
``` java
|
||||
public class Foo { // This has a Cyclomatic Complexity = 12
|
||||
1 public void example() {
|
||||
2 if (a == b) {
|
||||
3 if (a1 == b1) {
|
||||
fiddle();
|
||||
4 } else if a2 == b2) {
|
||||
fiddle();
|
||||
} else {
|
||||
fiddle();
|
||||
}
|
||||
5 } else if (c == d) {
|
||||
6 while (c == d) {
|
||||
fiddle();
|
||||
}
|
||||
7 } else if (e == f) {
|
||||
8 for (int n = 0; n < h; n++) {
|
||||
fiddle();
|
||||
}
|
||||
} else{
|
||||
switch (z) {
|
||||
9 case 1:
|
||||
fiddle();
|
||||
break;
|
||||
10 case 2:
|
||||
fiddle();
|
||||
break;
|
||||
11 case 3:
|
||||
fiddle();
|
||||
break;
|
||||
12 default:
|
||||
fiddle();
|
||||
break;
|
||||
}
|
||||
class Foo {
|
||||
void baseCyclo() { // Cyclo = 1
|
||||
highCyclo();
|
||||
}
|
||||
|
||||
void highCyclo() { // Cyclo = 10: reported!
|
||||
int x = 0, y = 2;
|
||||
boolean a = false, b = true;
|
||||
|
||||
if (a && (y == 1 ? b : true)) { // +3
|
||||
if (y == x) { // +1
|
||||
while (true) { // +1
|
||||
if (x++ < 20) { // +1
|
||||
break; // +1
|
||||
}
|
||||
}
|
||||
} else if (y == t && !d) { // +2
|
||||
x = a ? y : x; // +1
|
||||
} else {
|
||||
x = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@ -426,9 +423,10 @@ public class Foo { // This has a Cyclomatic Complexity = 12
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|showMethodsComplexity|true|Add method average violations to the report|
|
||||
|showClassesComplexity|true|Add class average violations to the report|
|
||||
|reportLevel|10|Cyclomatic Complexity reporting threshold|
|
||||
|cycloOptions|[]|Choose options for the computation of Cyclo|
|
||||
|classReportLevel|80|Total class complexity reporting threshold|
|
||||
|methodReportLevel|10|Cyclomatic complexity reporting threshold|
|
||||
|reportLevel|10|<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> Cyclomatic Complexity reporting threshold|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
@ -1198,13 +1196,13 @@ public class Foo extends Bar {
|
||||
**Priority:** Medium (3)
|
||||
|
||||
The NPath complexity of a method is the number of acyclic execution paths through that method.
|
||||
While cyclomatic complexity counts the number of decision points in a method, NPath counts the number of
|
||||
full paths from the beginning to the end of the block of the method. That metric grows exponentially, as
|
||||
it multiplies the complexity of statements in the same block. For more details on the calculation, see the
|
||||
documentation of the [NPath metric](/pmd_java_metrics_index.html#npath-complexity-npath).
|
||||
While cyclomatic complexity counts the number of decision points in a method, NPath counts the number of
|
||||
full paths from the beginning to the end of the block of the method. That metric grows exponentially, as
|
||||
it multiplies the complexity of statements in the same block. For more details on the calculation, see the
|
||||
documentation of the [NPath metric](/pmd_java_metrics_index.html#npath-complexity-npath).
|
||||
|
||||
A threshold of 200 is generally considered the point where measures should be taken to reduce
|
||||
complexity and increase readability.
|
||||
A threshold of 200 is generally considered the point where measures should be taken to reduce
|
||||
complexity and increase readability.
|
||||
|
||||
**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.NPathComplexityRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/NPathComplexityRule.java)
|
||||
|
||||
@ -1251,7 +1249,7 @@ public class Foo {
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|minimum|200.0|Deprecated! Minimum reporting threshold|
|
||||
|minimum|200.0|<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> Minimum reporting threshold|
|
||||
|reportLevel|200|N-Path Complexity reporting threshold|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
|
@ -60,12 +60,14 @@ Denotes whether comments are required (or unwanted) for specific language elemen
|
||||
|
||||
|Name|Default Value|Description|
|
||||
|----|-------------|-----------|
|
||||
|serialVersionUIDCommentRequired|Ignored|serial version UID commts. Possible values: [Required, Ignored, Unwanted]|
|
||||
|serialVersionUIDCommentRequired|Ignored|Serial version UID comments. Possible values: [Required, Ignored, Unwanted]|
|
||||
|enumCommentRequirement|Required|Enum comments. Possible values: [Required, Ignored, Unwanted]|
|
||||
|protectedMethodCommentRequirement|Required|Protected method constructor comments. Possible values: [Required, Ignored, Unwanted]|
|
||||
|publicMethodCommentRequirement|Required|Public method and constructor comments. Possible values: [Required, Ignored, Unwanted]|
|
||||
|fieldCommentRequirement|Required|Field comments. Possible values: [Required, Ignored, Unwanted]|
|
||||
|headerCommentRequirement|Required|Header comments. Possible values: [Required, Ignored, Unwanted]|
|
||||
|methodWithOverrideCommentRequirement|Ignored|Comments on @Override methods. Possible values: [Required, Ignored, Unwanted]|
|
||||
|accessorCommentRequirement|Ignored|Comments on getters and setters". Possible values: [Required, Ignored, Unwanted]|
|
||||
|
||||
**Use this rule by referencing it:**
|
||||
``` xml
|
||||
|
@ -3,33 +3,51 @@ title: Java Server Pages Rules
|
||||
permalink: pmd_rules_jsp.html
|
||||
folder: pmd/rules
|
||||
---
|
||||
List of rulesets and rules contained in each ruleset.
|
||||
|
||||
* [Best Practices](pmd_rules_jsp_bestpractices.html): Rules which enforce generally accepted best practices.
|
||||
* [Codestyle](pmd_rules_jsp_codestyle.html): Rules which enforce a specific coding style.
|
||||
* [Design](pmd_rules_jsp_design.html): Rules that help you discover design issues.
|
||||
* [Error Prone](pmd_rules_jsp_errorprone.html): Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
|
||||
* [Security](pmd_rules_jsp_security.html): Rules that flag potential security flaws.
|
||||
|
||||
## Best Practices
|
||||
|
||||
{% include callout.html content="Rules which enforce generally accepted best practices." %}
|
||||
|
||||
* [DontNestJsfInJstlIteration](pmd_rules_jsp_bestpractices.html#dontnestjsfinjstliteration): Do not nest JSF component custom actions inside a custom action that iterates over its body.
|
||||
* [NoClassAttribute](pmd_rules_jsp_bestpractices.html#noclassattribute): Do not use an attribute called 'class'. Use "styleclass" for CSS styles.
|
||||
* [NoHtmlComments](pmd_rules_jsp_bestpractices.html#nohtmlcomments): In a production system, HTML comments increase the payloadbetween the application server to the c...
|
||||
* [NoJspForward](pmd_rules_jsp_bestpractices.html#nojspforward): Do not do a forward from within a JSP file.
|
||||
|
||||
## Codestyle
|
||||
|
||||
{% include callout.html content="Rules which enforce a specific coding style." %}
|
||||
|
||||
* [DuplicateJspImports](pmd_rules_jsp_codestyle.html#duplicatejspimports): Avoid duplicate import statements inside JSP's.
|
||||
|
||||
## Design
|
||||
|
||||
{% include callout.html content="Rules that help you discover design issues." %}
|
||||
|
||||
* [NoInlineScript](pmd_rules_jsp_design.html#noinlinescript): Avoid inlining HTML script content. Consider externalizing the HTML script using the 'src' attri...
|
||||
* [NoInlineStyleInformation](pmd_rules_jsp_design.html#noinlinestyleinformation): Style information should be put in CSS files, not in JSPs. Therefore, don't use <B> or <FONT>tags...
|
||||
* [NoLongScripts](pmd_rules_jsp_design.html#nolongscripts): Scripts should be part of Tag Libraries, rather than part of JSP pages.
|
||||
* [NoScriptlets](pmd_rules_jsp_design.html#noscriptlets): Scriptlets should be factored into Tag Libraries or JSP declarations, rather than being part of J...
|
||||
|
||||
## Error Prone
|
||||
|
||||
{% include callout.html content="Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors." %}
|
||||
|
||||
* [JspEncoding](pmd_rules_jsp_errorprone.html#jspencoding): A missing 'meta' tag or page directive will trigger this rule, as well as a non-UTF-8 charset.
|
||||
|
||||
## Security
|
||||
|
||||
{% include callout.html content="Rules that flag potential security flaws." %}
|
||||
|
||||
* [IframeMissingSrcAttribute](pmd_rules_jsp_security.html#iframemissingsrcattribute): IFrames which are missing a src element can cause security information popups in IE if you are ac...
|
||||
* [NoUnsanitizedJSPExpression](pmd_rules_jsp_security.html#nounsanitizedjspexpression): Avoid using expressions without escaping / sanitizing. This could lead to cross site scripting - ...
|
||||
|
||||
## Additional rulesets
|
||||
|
||||
* Basic JSP (`rulesets/jsp/basic.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[DuplicateJspImports](pmd_rules_jsp_codestyle.html#duplicatejspimports), [IframeMissingSrcAttribute](pmd_rules_jsp_security.html#iframemissingsrcattribute), [JspEncoding](pmd_rules_jsp_errorprone.html#jspencoding), [NoClassAttribute](pmd_rules_jsp_bestpractices.html#noclassattribute), [NoHtmlComments](pmd_rules_jsp_bestpractices.html#nohtmlcomments), [NoInlineScript](pmd_rules_jsp_design.html#noinlinescript), [NoInlineStyleInformation](pmd_rules_jsp_design.html#noinlinestyleinformation), [NoJspForward](pmd_rules_jsp_bestpractices.html#nojspforward), [NoLongScripts](pmd_rules_jsp_design.html#nolongscripts), [NoScriptlets](pmd_rules_jsp_design.html#noscriptlets), [NoUnsanitizedJSPExpression](pmd_rules_jsp_security.html#nounsanitizedjspexpression)
|
||||
|
||||
|
||||
|
@ -3,20 +3,22 @@ title: PLSQL Rules
|
||||
permalink: pmd_rules_plsql.html
|
||||
folder: pmd/rules
|
||||
---
|
||||
List of rulesets and rules contained in each ruleset.
|
||||
|
||||
* [Best Practices](pmd_rules_plsql_bestpractices.html): Rules which enforce generally accepted best practices.
|
||||
* [Codestyle](pmd_rules_plsql_codestyle.html): Rules which enforce a specific coding style.
|
||||
* [Design](pmd_rules_plsql_design.html): Rules that help you discover design issues.
|
||||
* [Error Prone](pmd_rules_plsql_errorprone.html): Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
|
||||
|
||||
## Best Practices
|
||||
|
||||
{% include callout.html content="Rules which enforce generally accepted best practices." %}
|
||||
|
||||
* [TomKytesDespair](pmd_rules_plsql_bestpractices.html#tomkytesdespair): "WHEN OTHERS THEN NULL" hides all errors - (Re)RAISE an exception or call RAISE_APPLICATION_ERROR
|
||||
|
||||
## Codestyle
|
||||
|
||||
{% include callout.html content="Rules which enforce a specific coding style." %}
|
||||
|
||||
* [MisplacedPragma](pmd_rules_plsql_codestyle.html#misplacedpragma): Oracle states that the PRAQMA AUTONOMOUS_TRANSACTION must be in the declaration block,but the cod...
|
||||
|
||||
## Design
|
||||
|
||||
{% include callout.html content="Rules that help you discover design issues." %}
|
||||
|
||||
* [CyclomaticComplexity](pmd_rules_plsql_design.html#cyclomaticcomplexity): Complexity directly affects maintenance costs is determined by the number of decision points in a...
|
||||
* [ExcessiveMethodLength](pmd_rules_plsql_design.html#excessivemethodlength): When methods are excessively long this usually indicates that the method is doing more than itsna...
|
||||
* [ExcessiveObjectLength](pmd_rules_plsql_design.html#excessiveobjectlength): Excessive object line lengths are usually indications that the object may be burdened with excess...
|
||||
@ -31,7 +33,45 @@ List of rulesets and rules contained in each ruleset.
|
||||
* [TooManyMethods](pmd_rules_plsql_design.html#toomanymethods): A package or type with too many methods is probably a good suspect for refactoring, in order to r...
|
||||
|
||||
## Error Prone
|
||||
|
||||
{% include callout.html content="Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors." %}
|
||||
|
||||
* [TO_DATE_TO_CHAR](pmd_rules_plsql_errorprone.html#to_date_to_char): TO_DATE(TO_CHAR(date-variable)) used to remove time component - use TRUNC(date-variable)
|
||||
* [TO_DATEWithoutDateFormat](pmd_rules_plsql_errorprone.html#to_datewithoutdateformat): TO_DATE without date format- use TO_DATE(expression, date-format)
|
||||
* [TO_TIMESTAMPWithoutDateFormat](pmd_rules_plsql_errorprone.html#to_timestampwithoutdateformat): TO_TIMESTAMP without date format- use TO_TIMESTAMP(expression, date-format)
|
||||
|
||||
## Additional rulesets
|
||||
|
||||
* Code Size (`rulesets/plsql/codesize.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[CyclomaticComplexity](pmd_rules_plsql_design.html#cyclomaticcomplexity), [ExcessiveMethodLength](pmd_rules_plsql_design.html#excessivemethodlength), [ExcessiveObjectLength](pmd_rules_plsql_design.html#excessiveobjectlength), [ExcessivePackageBodyLength](pmd_rules_plsql_design.html#excessivepackagebodylength), [ExcessivePackageSpecificationLength](pmd_rules_plsql_design.html#excessivepackagespecificationlength), [ExcessiveParameterList](pmd_rules_plsql_design.html#excessiveparameterlist), [ExcessiveTypeLength](pmd_rules_plsql_design.html#excessivetypelength), [NcssMethodCount](pmd_rules_plsql_design.html#ncssmethodcount), [NcssObjectCount](pmd_rules_plsql_design.html#ncssobjectcount), [NPathComplexity](pmd_rules_plsql_design.html#npathcomplexity), [TooManyFields](pmd_rules_plsql_design.html#toomanyfields), [TooManyMethods](pmd_rules_plsql_design.html#toomanymethods)
|
||||
|
||||
* PLSQL DATETIME (`rulesets/plsql/dates.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[TO_DATE_TO_CHAR](pmd_rules_plsql_errorprone.html#to_date_to_char), [TO_DATEWithoutDateFormat](pmd_rules_plsql_errorprone.html#to_datewithoutdateformat), [TO_TIMESTAMPWithoutDateFormat](pmd_rules_plsql_errorprone.html#to_timestampwithoutdateformat)
|
||||
|
||||
* Strict Syntax (`rulesets/plsql/strictsyntax.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[MisplacedPragma](pmd_rules_plsql_codestyle.html#misplacedpragma)
|
||||
|
||||
* Tom Kyte's Despair (`rulesets/plsql/TomKytesDespair.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[TomKytesDespair](pmd_rules_plsql_bestpractices.html#tomkytesdespair)
|
||||
|
||||
|
||||
|
@ -3,11 +3,21 @@ title: Maven POM Rules
|
||||
permalink: pmd_rules_pom.html
|
||||
folder: pmd/rules
|
||||
---
|
||||
List of rulesets and rules contained in each ruleset.
|
||||
|
||||
* [Errorprone](pmd_rules_pom_errorprone.html): Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
|
||||
|
||||
## Errorprone
|
||||
|
||||
{% include callout.html content="Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors." %}
|
||||
|
||||
* [InvalidDependencyTypes](pmd_rules_pom_errorprone.html#invaliddependencytypes): If you use an invalid dependency type in the dependency management section, Maven doesn't fail. I...
|
||||
* [ProjectVersionAsDependencyVersion](pmd_rules_pom_errorprone.html#projectversionasdependencyversion): Using that expression in dependency declarations seems like a shortcut, but it can go wrong.By fa...
|
||||
|
||||
## Additional rulesets
|
||||
|
||||
* Basic POM (`rulesets/pom/basic.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[InvalidDependencyTypes](pmd_rules_pom_errorprone.html#invaliddependencytypes), [ProjectVersionAsDependencyVersion](pmd_rules_pom_errorprone.html#projectversionasdependencyversion)
|
||||
|
||||
|
||||
|
@ -3,11 +3,21 @@ title: Salesforce VisualForce Rules
|
||||
permalink: pmd_rules_vf.html
|
||||
folder: pmd/rules
|
||||
---
|
||||
List of rulesets and rules contained in each ruleset.
|
||||
|
||||
* [Security](pmd_rules_vf_security.html): Rules that flag potential security flaws.
|
||||
|
||||
## Security
|
||||
|
||||
{% include callout.html content="Rules that flag potential security flaws." %}
|
||||
|
||||
* [VfCsrf](pmd_rules_vf_security.html#vfcsrf): Avoid calling VF action upon page load as the action becomes vulnerable to CSRF.
|
||||
* [VfUnescapeEl](pmd_rules_vf_security.html#vfunescapeel): Avoid unescaped user controlled content in EL as it results in XSS.
|
||||
|
||||
## Additional rulesets
|
||||
|
||||
* Basic VF (`rulesets/vf/security.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[VfCsrf](pmd_rules_vf_security.html#vfcsrf), [VfUnescapeEl](pmd_rules_vf_security.html#vfunescapeel)
|
||||
|
||||
|
||||
|
@ -3,17 +3,17 @@ title: VM Rules
|
||||
permalink: pmd_rules_vm.html
|
||||
folder: pmd/rules
|
||||
---
|
||||
List of rulesets and rules contained in each ruleset.
|
||||
|
||||
* [Best Practices](pmd_rules_vm_bestpractices.html): Rules which enforce generally accepted best practices.
|
||||
* [Design](pmd_rules_vm_design.html): Rules that help you discover design issues.
|
||||
* [Errorprone](pmd_rules_vm_errorprone.html): Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
|
||||
|
||||
## Best Practices
|
||||
|
||||
{% include callout.html content="Rules which enforce generally accepted best practices." %}
|
||||
|
||||
* [AvoidReassigningParameters](pmd_rules_vm_bestpractices.html#avoidreassigningparameters): Reassigning values to incoming parameters is not recommended. Use temporary local variables inst...
|
||||
* [UnusedMacroParameter](pmd_rules_vm_bestpractices.html#unusedmacroparameter): Avoid unused macro parameters. They should be deleted.
|
||||
|
||||
## Design
|
||||
|
||||
{% include callout.html content="Rules that help you discover design issues." %}
|
||||
|
||||
* [AvoidDeeplyNestedIfStmts](pmd_rules_vm_design.html#avoiddeeplynestedifstmts): Avoid creating deeply nested if-then statements since they are harder to read and error-prone to ...
|
||||
* [CollapsibleIfStatements](pmd_rules_vm_design.html#collapsibleifstatements): Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with...
|
||||
* [ExcessiveTemplateLength](pmd_rules_vm_design.html#excessivetemplatelength): The template is too long. It should be broken up into smaller pieces.
|
||||
@ -21,6 +21,20 @@ List of rulesets and rules contained in each ruleset.
|
||||
* [NoInlineStyles](pmd_rules_vm_design.html#noinlinestyles): Avoid inline styles. Use css classes instead.
|
||||
|
||||
## Errorprone
|
||||
|
||||
{% include callout.html content="Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors." %}
|
||||
|
||||
* [EmptyForeachStmt](pmd_rules_vm_errorprone.html#emptyforeachstmt): Empty foreach statements should be deleted.
|
||||
* [EmptyIfStmt](pmd_rules_vm_errorprone.html#emptyifstmt): Empty if statements should be deleted.
|
||||
|
||||
## Additional rulesets
|
||||
|
||||
* Basic Velocity (`rulesets/vm/basic.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[AvoidDeeplyNestedIfStmts](pmd_rules_vm_design.html#avoiddeeplynestedifstmts), [AvoidReassigningParameters](pmd_rules_vm_bestpractices.html#avoidreassigningparameters), [CollapsibleIfStatements](pmd_rules_vm_design.html#collapsibleifstatements), [EmptyForeachStmt](pmd_rules_vm_errorprone.html#emptyforeachstmt), [EmptyIfStmt](pmd_rules_vm_errorprone.html#emptyifstmt), [ExcessiveTemplateLength](pmd_rules_vm_design.html#excessivetemplatelength), [NoInlineJavaScript](pmd_rules_vm_design.html#noinlinejavascript), [NoInlineStyles](pmd_rules_vm_design.html#noinlinestyles), [UnusedMacroParameter](pmd_rules_vm_bestpractices.html#unusedmacroparameter)
|
||||
|
||||
|
||||
|
@ -3,10 +3,20 @@ title: XML Rules
|
||||
permalink: pmd_rules_xml.html
|
||||
folder: pmd/rules
|
||||
---
|
||||
List of rulesets and rules contained in each ruleset.
|
||||
|
||||
* [Errorprone](pmd_rules_xml_errorprone.html): Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
|
||||
|
||||
## Errorprone
|
||||
|
||||
{% include callout.html content="Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors." %}
|
||||
|
||||
* [MistypedCDATASection](pmd_rules_xml_errorprone.html#mistypedcdatasection): An XML CDATA section begins with a <!CDATA[ marker, which has only one [, and ends with a ]]> mar...
|
||||
|
||||
## Additional rulesets
|
||||
|
||||
* Basic XML (`rulesets/xml/basic.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[MistypedCDATASection](pmd_rules_xml_errorprone.html#mistypedcdatasection)
|
||||
|
||||
|
||||
|
@ -3,14 +3,26 @@ title: XSL Rules
|
||||
permalink: pmd_rules_xsl.html
|
||||
folder: pmd/rules
|
||||
---
|
||||
List of rulesets and rules contained in each ruleset.
|
||||
|
||||
* [Codestyle](pmd_rules_xsl_codestyle.html): Rules which enforce a specific coding style.
|
||||
* [Performance](pmd_rules_xsl_performance.html): Rules that flag suboptimal code.
|
||||
|
||||
## Codestyle
|
||||
|
||||
{% include callout.html content="Rules which enforce a specific coding style." %}
|
||||
|
||||
* [UseConcatOnce](pmd_rules_xsl_codestyle.html#useconcatonce): The XPath concat() functions accepts as many arguments as required so you can have"concat($a,'b',...
|
||||
|
||||
## Performance
|
||||
|
||||
{% include callout.html content="Rules that flag suboptimal code." %}
|
||||
|
||||
* [AvoidAxisNavigation](pmd_rules_xsl_performance.html#avoidaxisnavigation): Avoid using the 'following' or 'preceeding' axes whenever possible, as these can cutthrough 100% ...
|
||||
|
||||
## Additional rulesets
|
||||
|
||||
* XPath in XSL (`rulesets/xsl/xpath.xml`):
|
||||
|
||||
<span style="border-radius: 0.25em; color: #fff; padding: 0.2em 0.6em 0.3em; display: inline; background-color: #d9534f; font-size: 75%;">Deprecated</span> This ruleset is for backwards compatibility.
|
||||
|
||||
It contains the following rules:
|
||||
|
||||
[AvoidAxisNavigation](pmd_rules_xsl_performance.html#avoidaxisnavigation), [UseConcatOnce](pmd_rules_xsl_codestyle.html#useconcatonce)
|
||||
|
||||
|
||||
|
@ -2,23 +2,30 @@
|
||||
title: Best Practices
|
||||
permalink: pmd_userdocs_best_practices.html
|
||||
author: Tom Copeland <tom@infoether.com>
|
||||
last_updated: November 2017
|
||||
---
|
||||
|
||||
## Choose the rules that are right for you
|
||||
|
||||
Running every ruleset will result in a huge number of rule violations, most of which will be unimportant.
|
||||
Running every existing rule will result in a huge number of rule violations, most of which will be unimportant.
|
||||
Having to sort through a thousand line report to find the few you're really interested in takes
|
||||
all the fun out of things.
|
||||
|
||||
Instead, start with some of the obvious rulesets - just run [unusedcode](/pmd_rules_java.html#unused-code) and fix any unused locals and fields.
|
||||
Then, run [empty](/pmd_rules_java.html#empty-code) and fix all the empty `if` statements and such-like. After that, take [unnecessary](/pmd_rules_java.html#unnecessary)
|
||||
and fix these violations. Then, run [basic](/pmd_rules_java.html#basic) and fix the remaining violations.
|
||||
Then peruse the [design](/pmd_rules_java.html#design) and [controversial](/pmd_rules_java.html#controversial) rulesets and use the ones
|
||||
you like [via a custom ruleset](/pmd_userdocs_understanding_rulesets.html).
|
||||
Instead, start with some selected specific rules, e.g. the rules that detect unused code from
|
||||
the category [Best Practices](pmd_rules_java_bestpractices.html) and fix any unused locals and fields.
|
||||
|
||||
Then, run rules, that detect empty `if` statements and such-like. You can find these rules in the category
|
||||
[Error Prone](pmd_rules_java_errorprone.html).
|
||||
|
||||
After that, look at all the categories and select the rules, that are useful for your project.
|
||||
You can find an overview of the rules on the [Rule Index](pmd_rules_java.html).
|
||||
|
||||
Use the rules you like [via a custom ruleset](pmd_userdocs_understanding_rulesets.html).
|
||||
|
||||
## PMD rules are not set in stone
|
||||
|
||||
Generally, pick the ones you like, and ignore or [suppress](/pmd_userdocs_suppressing.html) the warnings you don't like. It's just a tool.
|
||||
Generally, pick the ones you like, and ignore or [suppress](pmd_userdocs_suppressing.html)
|
||||
the warnings you don't like. It's just a tool.
|
||||
|
||||
## PMD IDE plugins are nice
|
||||
|
||||
|
@ -243,21 +243,25 @@ This behavior has been introduced to ease CPD integration into scripts or hooks,
|
||||
|
||||
### Supported Languages
|
||||
|
||||
* cs
|
||||
* cpp
|
||||
* ecmascript (JavaScript)
|
||||
* fortran
|
||||
* go
|
||||
* java
|
||||
* jsp
|
||||
* matlab
|
||||
* objectivec
|
||||
* php
|
||||
* plsql
|
||||
* python
|
||||
* ruby
|
||||
* scala
|
||||
* swift
|
||||
* Apex
|
||||
* C#
|
||||
* C/C++
|
||||
* EcmaScript (JavaScript)
|
||||
* Fortran
|
||||
* Go
|
||||
* Groovy
|
||||
* Java
|
||||
* Jsp
|
||||
* Matlab
|
||||
* Objective-C
|
||||
* Perl
|
||||
* PHP
|
||||
* PL/SQL
|
||||
* Python
|
||||
* Ruby
|
||||
* Scala
|
||||
* Swift
|
||||
* Visualforce
|
||||
|
||||
|
||||
### Available formats
|
||||
|
@ -345,7 +345,7 @@ PMD comes with many different renderer types:
|
||||
* outputDir: Output directory.
|
||||
|
||||
|
||||
### Incremenal Analysis
|
||||
### Incremental Analysis
|
||||
|
||||
Ever since PMD 5.6.0, PMD has been able to perform Incremental Analysis.
|
||||
|
||||
|
@ -1,20 +1,45 @@
|
||||
---
|
||||
title: Understanding Rulesets
|
||||
permalink: pmd_userdocs_understanding_rulesets.html
|
||||
summary: Rulesets are collections of rules
|
||||
last_updated: September 2017
|
||||
summary: Rules belong to categories and rulesets are custom collections of rules
|
||||
last_updated: November 2017
|
||||
---
|
||||
|
||||
## Rule Categories
|
||||
|
||||
Since PMD 6.0.0, all provided built-in rules are sorted into one of eight categories:
|
||||
|
||||
1. **Best Practices**: These are rules which enforce generally accepted best practices.
|
||||
2. **Code Style**: These rules enforce a specific coding style.
|
||||
3. **Design**: Rules that help you discover design issues.
|
||||
4. **Documentation**: These rules are related to code documentation.
|
||||
5. **Error Prone**: Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
|
||||
6. **Multithreading**: These are rules that flag issues when dealing with multiple threads of execution.
|
||||
7. **Performance**: Rules that flag suboptimal code.
|
||||
8. **Security**: Rules that flag potential security flaws.
|
||||
|
||||
These categories help you to find rules and figure out the relevance and impact for your project.
|
||||
|
||||
You can find the available rules under "Rule Reference" in the menu. Each languages has its own rule
|
||||
index, e.g. [Java Rules](pmd_rules_java.html) or [JavaScript Rules](pmd_rules_ecmascript.html).
|
||||
|
||||
{% include note.html content="Not all supported languages provide rules in all categories yet. " %}
|
||||
|
||||
|
||||
## Rulesets
|
||||
|
||||
There are two major use cases:
|
||||
|
||||
1. When defining a new rule, the rule needs to be defined in a ruleset. PMD's built-in rules
|
||||
are defined in specific rulesets from which the rule reference documentation is generated,
|
||||
are defined in special rulesets which form the eight categories mentioned above.
|
||||
From these rulesets the rule reference documentation is generated,
|
||||
see [Java Rules](pmd_rules_java.html) for an example.
|
||||
|
||||
Similar rules are grouped together into the same ruleset, like the [Java Braces Ruleset](pmd_rules_java_braces.html)
|
||||
which contains rules that all deal with missing braces.
|
||||
Similar rules are grouped together into the same category, like [Java Best Practices](pmd_rules_java_bestpractices.html)
|
||||
which contains rules which enforce generally accepted best practices. Each category uses its own
|
||||
ruleset file.
|
||||
|
||||
2. When executing PMD you need to tell, which rules should be executed. You could directly point to the
|
||||
2. When executing PMD, you need to tell, which rules should be executed. You could directly point to the
|
||||
built-in rulesets, but then you might be overwhelmed by the found violations. As described
|
||||
in [Best Practices](pmd_userdocs_best_practices.html), it's better to define an own custom ruleset.
|
||||
|
||||
@ -42,11 +67,11 @@ Custom rules
|
||||
```
|
||||
|
||||
Now start to add rule by **referencing** them. Let's say, you want to start with finding
|
||||
[Empty Catch Blocks](pmd_rules_java_empty.html#emptycatchblock). Then you'd add the following
|
||||
[Empty Catch Blocks](pmd_rules_java_errorprone.html#emptycatchblock). Then you'd add the following
|
||||
rule reference inside the `ruleset` elements:
|
||||
|
||||
```xml
|
||||
<rule ref="rulesets/java/empty.xml/EmptyCatchBlock" />
|
||||
<rule ref="category/java/errorprone.xml/EmptyCatchBlock" />
|
||||
```
|
||||
|
||||
## Adjusting rule properties
|
||||
@ -56,7 +81,7 @@ of `ignored` will not raise a violation. Therefore you would reference the rule
|
||||
the appropriate property value:
|
||||
|
||||
```xml
|
||||
<rule ref="rulesets/java/empty.xml/EmptyCatchBlock">
|
||||
<rule ref="category/java/errorprone.xml/EmptyCatchBlock">
|
||||
<properties>
|
||||
<property name="allowExceptionNameRegex">
|
||||
<value>^ignored$</value>
|
||||
|
@ -19,6 +19,7 @@ This is a major release.
|
||||
* [Metrics Framework](#metrics-framework)
|
||||
* [Error Reporting](#error-reporting)
|
||||
* [Apex Rule Suppression](#apex-rule-suppression)
|
||||
* [Rule Categories](#rule-categories)
|
||||
* [New Rules](#new-rules)
|
||||
* [Modified Rules](#modified-rules)
|
||||
* [Deprecated Rules](#deprecated-rules)
|
||||
@ -37,7 +38,7 @@ This is a major release.
|
||||
The Java grammar has been updated to support analyzing Java 9 projects:
|
||||
|
||||
* private methods in interfaces are possible
|
||||
* The underscore "_" is considered an invalid identifier
|
||||
* The underscore "\_" is considered an invalid identifier
|
||||
* Diamond operator for anonymous classes
|
||||
* The module declarations in `module-info.java` can be parsed
|
||||
* Concise try-with-resources statements are supported
|
||||
@ -130,93 +131,133 @@ Supported syntax includes:
|
||||
|
||||
Notice this last scenario is slightly different to the Java syntax. This is due to differences in the Apex grammar for annotations.
|
||||
|
||||
#### Rule Categories
|
||||
|
||||
All built-in rules have been sorted into one of eight categories:
|
||||
|
||||
1. **Best Practices**: These are rules which enforce generally accepted best practices.
|
||||
2. **Code Style**: These rules enforce a specific coding style.
|
||||
3. **Design**: Rules that help you discover design issues.
|
||||
4. **Documentation**: These rules are related to code documentation.
|
||||
5. **Error Prone**: Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
|
||||
6. **Multithreading**: These are rules that flag issues when dealing with multiple threads of execution.
|
||||
7. **Performance**: Rules that flag suboptimal code.
|
||||
8. **Security**: Rules that flag potential security flaws.
|
||||
|
||||
These categories help you to find rules and figure out the relevance and impact for your project.
|
||||
|
||||
All rules have been moved accordingly, e.g. the rule "JumbledIncrementer", which was previously defined in the
|
||||
ruleset "java-basic" has now been moved to the "Error Prone" category. The new rule reference to be used is
|
||||
`<rule ref="category/java/errorprone.xml/JumbledIncrementer"/>`.
|
||||
|
||||
The old rulesets like "java-basic" are still kept for backwards-compatibility but will be removed eventually.
|
||||
The rule reference documentation has been updated to reflect these changes.
|
||||
|
||||
#### New Rules
|
||||
|
||||
* The rule `NcssCount` (ruleset `java-codesize`) replaces the three rules "NcssConstructorCount", "NcssMethodCount",
|
||||
* The new Java rule `NcssCount` (category `design`) replaces the three rules "NcssConstructorCount", "NcssMethodCount",
|
||||
and "NcssTypeCount". The new rule uses the metrics framework to achieve the same. It has two properties, to
|
||||
define the report level for method and class sizes separately. Constructors and methods are considered the same.
|
||||
|
||||
* The new rule `DoNotExtendJavaLangThrowable` (ruleset `java-strictexception`) is a companion for the
|
||||
* The new Java rule `DoNotExtendJavaLangThrowable` (category `errorprone`) is a companion for the
|
||||
`java-strictexception.xml/DoNotExtendJavaLangError`, detecting direct extensions of `java.lang.Throwable`.
|
||||
|
||||
* The new rule `ForLoopCanBeForeach` (ruleset `java-migration`) helps to identify those for-loops that can
|
||||
* The new Java rule `ForLoopCanBeForeach` (category `errorprone`) helps to identify those for-loops that can
|
||||
be safely refactored into for-each-loops available since java 1.5.
|
||||
|
||||
* The new rule `AvoidDirectAccessTriggerMap` (ruleset `apex-style`) helps to identify direct array access to triggers,
|
||||
which can produce bugs by iether accessing non-existing indexes, or them leaving out. You should use for-each-loops
|
||||
* The new Apex rule `AvoidDirectAccessTriggerMap` (category `errorprone`) helps to identify direct array access to triggers,
|
||||
which can produce bugs by either accessing non-existing indexes, or leaving them out. You should use for-each-loops
|
||||
instead.
|
||||
|
||||
* The new rule `AvoidHardcodingId` (ruleset `apex-style`) detects hardcoded strings that look like identifiers
|
||||
* The new Apex rule `AvoidHardcodingId` (category `errorprone`) detects hardcoded strings that look like identifiers
|
||||
and flags them. Record IDs change between environments, meaning hardcoded ids are bound to fail under a different
|
||||
setup.
|
||||
|
||||
* A whole new ruleset has been added to Apex, `apex-empty`. It currently migrates 5 rules from the equivalent
|
||||
`java-empty` ruleset for Apex. The ruleset includes:
|
||||
* A whole bunch of new rules has been added to Apex. They all fit into the category `errorprone`.
|
||||
The 5 rules are migrated for Apex from the equivalent Java rules and include:
|
||||
* `EmptyCatchBlock` to detect catch blocks completely ignoring exceptions.
|
||||
* `EmptyIfStmt` for if blocks with no content, that can be safely removed.
|
||||
* `EmptyTryOrFinallyBlock` for empty try / finally blocks that can be safely removed.
|
||||
* `EmptyWhileStmt` for empty while loops that can be safely removed.
|
||||
* `EmptyStatementBlock` for empty code blocks that can be safely removed.
|
||||
|
||||
* The new rule `AvoidSoslInLoops` (ruleset `apex-performance`) is the companion of the old
|
||||
`apex-performance/AvoidSoqlInLoops` rule, flagging SOSL (Salesforce Object Search Language) queries when within
|
||||
* The new Apex rule `AvoidSoslInLoops` (category `performance`) is the companion of the old
|
||||
`AvoidSoqlInLoops` rule, flagging SOSL (Salesforce Object Search Language) queries when within
|
||||
loops, to avoid governor issues, and hitting the database too often.
|
||||
|
||||
#### Modified Rules
|
||||
|
||||
* The rule `UnnecessaryFinalModifier` (ruleset `java-unnecessarycode`) has been merged into the rule
|
||||
`UnnecessaryModifier` of the same ruleset. As part of this, the rule has been revamped to detect more cases.
|
||||
* The Java rule `UnnecessaryFinalModifier` (category `codestyle`, former ruleset `java-unnecessarycode`)
|
||||
has been merged into the rule `UnnecessaryModifier`. As part of this, the rule has been revamped to detect more cases.
|
||||
It will now flag anonymous class' methods marked as final (can't be overridden, so it's pointless), along with
|
||||
final methods overridden / defined within enum instances. It will also flag `final` modifiers on try-with-resources.
|
||||
|
||||
* The rule `UnnecessaryParentheses` (ruleset `java-controversial`) has been merged into `UselessParentheses`
|
||||
(ruleset `java-unnecessary`). The rule covers all scenarios previously covered by either rule.
|
||||
* The Java rule `UnnecessaryParentheses` (category `codestyle`, former ruleset `java-controversial`)
|
||||
has been merged into `UselessParentheses` (category `codestyle`, former ruleset `java-unnecessary`).
|
||||
The rule covers all scenarios previously covered by either rule.
|
||||
|
||||
* The rule `UncommentedEmptyConstructor` (ruleset `java-design`) will now ignore empty constructors annotated with
|
||||
`javax.inject.Inject`.
|
||||
* The Java rule `UncommentedEmptyConstructor` (category `documentation`, former ruleset `java-design`)
|
||||
will now ignore empty constructors annotated with `javax.inject.Inject`.
|
||||
|
||||
* The rule `AbstractClassWithoutAnyMethod` (ruleset `java-design`) will now ignore classes annotated with
|
||||
`com.google.auto.value.AutoValue`.
|
||||
* The Java rule `AbstractClassWithoutAnyMethod` (category `bestpractices`, former ruleset `java-design`)
|
||||
will now ignore classes annotated with `com.google.auto.value.AutoValue`.
|
||||
|
||||
* The rule `GodClass` (ruleset `java-design`) has been revamped to use the new metrics framework.
|
||||
* The Java rule `GodClass` (category `design', former ruleset `java-design`) has been revamped to use
|
||||
the new metrics framework.
|
||||
|
||||
* The rule `LooseCoupling` (ruleset `java-coupling`) has been replaced by the typeresolution-based implementation.
|
||||
* The Java rule `LooseCoupling` (category `bestpractices`, former ruleset `java-coupling`) has been
|
||||
replaced by the typeresolution-based implementation.
|
||||
|
||||
* The rule `CloneMethodMustImplementCloneable` (ruleset `java-clone`) has been replaced by the typeresolution-based
|
||||
* The Java rule `CloneMethodMustImplementCloneable` (category `errorprone`, former ruleset `java-clone`)
|
||||
has been replaced by the typeresolution-based
|
||||
implementation and is now able to detect cases if a class implements or extends a Cloneable class/interface.
|
||||
|
||||
* The rule `UnusedImports` (ruleset `java-imports`) has been replaced by the typeresolution-based
|
||||
* The Java rule `UnusedImports` (category `bestpractices`, former ruleset `java-imports`) has been
|
||||
replaced by the typeresolution-based
|
||||
implementation and is now able to detect unused on-demand imports.
|
||||
|
||||
* The rule `SignatureDeclareThrowsException` (ruleset 'java-strictexception') has been replaced by the
|
||||
* The Java rule `SignatureDeclareThrowsException` (category `design`, former ruleset 'java-strictexception')
|
||||
has been replaced by the
|
||||
typeresolution-based implementation. It has a new property `IgnoreJUnitCompletely`, which allows all
|
||||
methods in a JUnit testcase to throws exceptions.
|
||||
methods in a JUnit testcase to throw exceptions.
|
||||
|
||||
* The rule `NPathComplexity` (ruleset `java-codesize`) has been revamped to use the new metrics framework.
|
||||
* The Java rule `NPathComplexity` (category `design`, former ruleset `java-codesize`) has been revamped
|
||||
to use the new metrics framework.
|
||||
Its report threshold can be configured via the property `reportLevel`, which replaces the now
|
||||
deprecated property `minimum`.
|
||||
|
||||
* The Java rule `CyclomaticComplexity` (category `design`, former ruleset `java-codesize`) has been
|
||||
revamped to use the new metrics framework.
|
||||
Its report threshold can be configured via the properties `classReportLevel` and `methodReportLevel` separately.
|
||||
The old property `reportLevel`, which configured the level for both total class and method complexity,
|
||||
is deprecated.
|
||||
|
||||
* The Java rule `CommentRequired` (category `documentation`, former ruleset `java-comments`)
|
||||
has been revamped to include 2 new properties:
|
||||
* `accessorCommentRequirement` to specify documentation requirements for getters and setters (default to `ignored`)
|
||||
* `methodWithOverrideCommentRequirement` to specify documentation requirements for methods annotated with `@Override` (default to `ignored`)
|
||||
|
||||
#### Deprecated Rules
|
||||
|
||||
* The rules `NcssConstructorCount`, `NcssMethodCount`, and `NcssTypeCount` (ruleset `java-codesize`) have been
|
||||
deprecated. They will be replaced by the new rule `NcssCount` in the same ruleset.
|
||||
* The Java rules `NcssConstructorCount`, `NcssMethodCount`, and `NcssTypeCount` (ruleset `java-codesize`) have been
|
||||
deprecated. They will be replaced by the new rule `NcssCount` in the category `design`.
|
||||
|
||||
* The rule `LooseCoupling` in ruleset `java-typeresolution` is deprecated. Use the rule with the same name
|
||||
from ruleset `java-coupling` instead.
|
||||
* The Java rule `LooseCoupling` in ruleset `java-typeresolution` is deprecated. Use the rule with the same name
|
||||
from category `bestpractices` instead.
|
||||
|
||||
* The rule `CloneMethodMustImplementCloneable` in ruleset `java-typeresolution` is deprecated. Use the rule with
|
||||
the same name from ruleset `java-clone` instead.
|
||||
* The Java rule `CloneMethodMustImplementCloneable` in ruleset `java-typeresolution` is deprecated. Use the rule with
|
||||
the same name from category `errorprone` instead.
|
||||
|
||||
* The rule `UnusedImports` in ruleset `java-typeresolution` is deprecated. Use the rule with
|
||||
the same name from ruleset `java-imports` instead.
|
||||
* The Java rule `UnusedImports` in ruleset `java-typeresolution` is deprecated. Use the rule with
|
||||
the same name from category `bestpractices` instead.
|
||||
|
||||
* The rule `SignatureDeclareThrowsException` in ruleset `java-typeresolution` is deprecated. Use the rule
|
||||
with the same name from ruleset `java-strictexception` instead.
|
||||
* The Java rule `SignatureDeclareThrowsException` in ruleset `java-typeresolution` is deprecated. Use the rule
|
||||
with the same name from category `design` instead.
|
||||
|
||||
#### Removed Rules
|
||||
|
||||
* The deprecated rule `UseSingleton` has been removed from the ruleset `java-design`. The rule has been renamed
|
||||
long time ago to `UseUtilityClass`.
|
||||
* The deprecated Java rule `UseSingleton` has been removed from the ruleset `java-design`. The rule has been renamed
|
||||
long time ago to `UseUtilityClass` (category `design`).
|
||||
|
||||
#### Java Symbol Table
|
||||
|
||||
@ -291,6 +332,7 @@ a warning will now be produced suggesting users to adopt it for better performan
|
||||
* java-basic
|
||||
* [#565](https://github.com/pmd/pmd/pull/565): \[java] False negative on DontCallThreadRun when extending Thread
|
||||
* java-comments
|
||||
* [#396](https://github.com/pmd/pmd/issues/396): \[java] CommentRequired: add properties to ignore @Override method and getters / setters
|
||||
* [#536](https://github.com/pmd/pmd/issues/536): \[java] CommentDefaultAccessModifierRule ignores constructors
|
||||
* java-controversial
|
||||
* [#388](https://github.com/pmd/pmd/issues/388): \[java] controversial.AvoidLiteralsInIfCondition 0.0 false positive
|
||||
@ -300,6 +342,8 @@ a warning will now be produced suggesting users to adopt it for better performan
|
||||
* [#357](https://github.com/pmd/pmd/issues/357): \[java] UncommentedEmptyConstructor consider annotations on Constructor
|
||||
* [#438](https://github.com/pmd/pmd/issues/438): \[java] Relax AbstractClassWithoutAnyMethod when class is annotated by @AutoValue
|
||||
* [#590](https://github.com/pmd/pmd/issues/590): \[java] False positive on MissingStaticMethodInNonInstantiatableClass
|
||||
* java-logging
|
||||
* [#721](https://github.com/pmd/pmd/issues/721): \[java] NPE in PMD 5.8.1 InvalidSlf4jMessageFormat
|
||||
* java-sunsecure
|
||||
* [#468](https://github.com/pmd/pmd/issues/468): \[java] ArrayIsStoredDirectly false positive
|
||||
* java-unusedcode
|
||||
@ -439,4 +483,12 @@ a warning will now be produced suggesting users to adopt it for better performan
|
||||
* [#694](https://github.com/pmd/pmd/pull/694): \[core] Add minor fixes to root pom - [Matias Comercio](https://github.com/MatiasComercio)
|
||||
* [#696](https://github.com/pmd/pmd/pull/696): \[core] Add remove operation over nodes - [Matias Comercio](https://github.com/MatiasComercio)
|
||||
* [#722](https://github.com/pmd/pmd/pull/722): \[java] Move NPathComplexity from metrics to design - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#723](https://github.com/pmd/pmd/pull/723): \[core] Rule factory refactoring - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#726](https://github.com/pmd/pmd/pull/726): \[java] Fix issue #721 (NPE in InvalidSlf4jMessageFormat) - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#727](https://github.com/pmd/pmd/pull/727): \[core] Fix #725: numeric property descriptors now check their default value - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#733](https://github.com/pmd/pmd/pull/733): \[java] Some improvements to CommentRequired - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#734](https://github.com/pmd/pmd/pull/734): \[java] Move CyclomaticComplexity from metrics to design - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#737](https://github.com/pmd/pmd/pull/737): \[doc] Fix NPathComplexity documentation bad rendering - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#744](https://github.com/pmd/pmd/pull/744): \[doc] Added Apex to supported languages - [Michał Kuliński](https://github.com/coola)
|
||||
* [#746](https://github.com/pmd/pmd/pull/746): \[doc] Fix typo in incremental analysis log message - [Clément Fournier](https://github.com/oowekyala)
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -22,7 +22,7 @@ public class NoopAnalysisCache implements AnalysisCache {
|
||||
|
||||
public NoopAnalysisCache() {
|
||||
LOG.warning("This analysis could be faster, please consider using Incremental Analysis: "
|
||||
+ "https://pmd.github.io/pmd/pmd_userdocs_getting_started.html#incremenal-analysis");
|
||||
+ "https://pmd.github.io/pmd/pmd_userdocs_getting_started.html#incremental-analysis");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,7 +20,7 @@ import net.sourceforge.pmd.properties.modules.NumericPropertyModule;
|
||||
* @version Refactored June 2017 (6.0.0)
|
||||
*/
|
||||
/* default */ abstract class AbstractMultiNumericProperty<T extends Number> extends AbstractMultiValueProperty<T>
|
||||
implements NumericPropertyDescriptor<List<T>> {
|
||||
implements NumericPropertyDescriptor<List<T>> {
|
||||
|
||||
private final NumericPropertyModule<T> module;
|
||||
|
||||
@ -43,6 +43,9 @@ import net.sourceforge.pmd.properties.modules.NumericPropertyModule;
|
||||
super(theName, theDescription, theDefault, theUIOrder, isDefinedExternally);
|
||||
|
||||
module = new NumericPropertyModule<>(lower, upper);
|
||||
for (T num : theDefault) {
|
||||
module.checkNumber(num);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,8 +43,10 @@ import net.sourceforge.pmd.properties.modules.NumericPropertyModule;
|
||||
super(theName, theDescription, theDefault, theUIOrder, isDefinedExternally);
|
||||
|
||||
module = new NumericPropertyModule<>(lower, upper);
|
||||
|
||||
|
||||
if (theDefault == null) {
|
||||
return; // TODO: remove me when you scrap StatisticalRule (see pull #727)
|
||||
}
|
||||
module.checkNumber(theDefault);
|
||||
}
|
||||
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user