Rules that are related to code documentation.

CommentContent

Since: PMD 5.0

Priority: Medium (3)

A rule for the politically correct… we don’t want to offend anyone.

This rule is defined by the following Java class: net.sourceforge.pmd.lang.java.rule.documentation.CommentContentRule

Example(s):

//OMG, this is horrible, Bob is an idiot !!!

This rule has the following properties:

Name Default Value Description Multivalued
caseSensitive false Case sensitive no
disallowedTerms idiot | jerk Illegal terms or phrases yes. Delimiter is ‘|’.

Use this rule with the default properties by just referencing it:

<rule ref="category/java/documentation.xml/CommentContent" />

Use this rule and customize it:

<rule ref="category/java/documentation.xml/CommentContent">
    <properties>
        <property name="caseSensitive" value="false" />
        <property name="disallowedTerms" value="idiot|jerk" />
    </properties>
</rule>

CommentRequired

Since: PMD 5.1

Priority: Medium (3)

Denotes whether javadoc (formal) comments are required (or unwanted) for specific language elements.

This rule is defined by the following Java class: net.sourceforge.pmd.lang.java.rule.documentation.CommentRequiredRule

Example(s):

/**
*
*
* @author Jon Doe
*/

This rule has the following properties:

Name Default Value Description Multivalued
methodWithOverrideCommentRequirement Ignored Comments on @Override methods. Possible values: [Required, Ignored, Unwanted] no
accessorCommentRequirement Ignored Comments on getters and setters". Possible values: [Required, Ignored, Unwanted] no
classCommentRequirement Required Class comments. Possible values: [Required, Ignored, Unwanted] no
headerCommentRequirement Required Deprecated Header comments. Please use the property "classCommentRequired" instead.. Possible values: [Required, Ignored, Unwanted] no
fieldCommentRequirement Required Field comments. Possible values: [Required, Ignored, Unwanted] no
publicMethodCommentRequirement Required Public method and constructor comments. Possible values: [Required, Ignored, Unwanted] no
protectedMethodCommentRequirement Required Protected method constructor comments. Possible values: [Required, Ignored, Unwanted] no
enumCommentRequirement Required Enum comments. Possible values: [Required, Ignored, Unwanted] no
serialVersionUIDCommentRequired Ignored Serial version UID comments. Possible values: [Required, Ignored, Unwanted] no
serialPersistentFieldsCommentRequired Ignored Serial persistent fields comments. Possible values: [Required, Ignored, Unwanted] no

Use this rule with the default properties by just referencing it:

<rule ref="category/java/documentation.xml/CommentRequired" />

Use this rule and customize it:

<rule ref="category/java/documentation.xml/CommentRequired">
    <properties>
        <property name="methodWithOverrideCommentRequirement" value="Ignored" />
        <property name="accessorCommentRequirement" value="Ignored" />
        <property name="classCommentRequirement" value="Required" />
        <property name="fieldCommentRequirement" value="Required" />
        <property name="publicMethodCommentRequirement" value="Required" />
        <property name="protectedMethodCommentRequirement" value="Required" />
        <property name="enumCommentRequirement" value="Required" />
        <property name="serialVersionUIDCommentRequired" value="Ignored" />
        <property name="serialPersistentFieldsCommentRequired" value="Ignored" />
    </properties>
</rule>

CommentSize

Since: PMD 5.0

Priority: Medium (3)

Determines whether the dimensions of non-header comments found are within the specified limits.

This rule is defined by the following Java class: net.sourceforge.pmd.lang.java.rule.documentation.CommentSizeRule

Example(s):

/**
*
*   too many lines!
*
*
*
*
*
*
*
*
*
*
*
*
*/

This rule has the following properties:

Name Default Value Description Multivalued
maxLines 6 Maximum lines no
maxLineLength 80 Maximum line length no

Use this rule with the default properties by just referencing it:

<rule ref="category/java/documentation.xml/CommentSize" />

Use this rule and customize it:

<rule ref="category/java/documentation.xml/CommentSize">
    <properties>
        <property name="maxLines" value="6" />
        <property name="maxLineLength" value="80" />
    </properties>
</rule>

UncommentedEmptyConstructor

Since: PMD 3.4

Priority: Medium (3)

Uncommented Empty Constructor finds instances where a constructor does not contain statements, but there is no comment. By explicitly commenting empty constructors it is easier to distinguish between intentional (commented) and unintentional empty constructors.

This rule is defined by the following XPath expression:

//ConstructorDeclaration[@Private= false()]
                        [@containsComment = false()]
                        [not(BlockStatement)]
                        [$ignoreExplicitConstructorInvocation = true() or not(ExplicitConstructorInvocation)]
                        [not(../Annotation/MarkerAnnotation/Name[
                                                                pmd-java:typeIs('javax.inject.Inject')
                                                             or pmd-java:typeIs('org.springframework.beans.factory.annotation.Autowired')
                                                                ])]

Example(s):

public Foo() {
  // This constructor is intentionally empty. Nothing special is needed here.
}

This rule has the following properties:

Name Default Value Description Multivalued
ignoreExplicitConstructorInvocation false Ignore explicit constructor invocation when deciding whether constructor is empty or not no

Use this rule with the default properties by just referencing it:

<rule ref="category/java/documentation.xml/UncommentedEmptyConstructor" />

Use this rule and customize it:

<rule ref="category/java/documentation.xml/UncommentedEmptyConstructor">
    <properties>
        <property name="ignoreExplicitConstructorInvocation" value="false" />
    </properties>
</rule>

UncommentedEmptyMethodBody

Since: PMD 3.4

Priority: Medium (3)

Uncommented Empty Method Body finds instances where a method body does not contain statements, but there is no comment. By explicitly commenting empty method bodies it is easier to distinguish between intentional (commented) and unintentional empty methods.

This rule is defined by the following XPath expression:

//MethodDeclaration/Block[count(BlockStatement) = 0 and @containsComment = false()]

Example(s):

public void doSomething() {
}

Use this rule by referencing it:

<rule ref="category/java/documentation.xml/UncommentedEmptyMethodBody" />