Movatterモバイル変換


[0]ホーム

URL:


 
» Documentation Edit on GitHub

Documentation

Rules that are related to code documentation.
Table of Contents

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:

NameDefault ValueDescription
forbiddenRegexidiot|jerkIllegal terms or phrases

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

<ruleref="category/java/documentation.xml/CommentContent"/>

Use this rule and customize it:

<ruleref="category/java/documentation.xml/CommentContent"><properties><propertyname="forbiddenRegex"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:

NameDefault ValueDescription
methodWithOverrideCommentRequirementIgnoredComments on @Override methods. Possible values: [Required, Ignored, Unwanted]
accessorCommentRequirementIgnoredComments on getters and setters". Possible values: [Required, Ignored, Unwanted]
classCommentRequirementRequiredClass comments. Possible values: [Required, Ignored, Unwanted]
fieldCommentRequirementRequiredField comments. Possible values: [Required, Ignored, Unwanted]
publicMethodCommentRequirementRequiredPublic method and constructor comments. Possible values: [Required, Ignored, Unwanted]
protectedMethodCommentRequirementRequiredProtected method constructor comments. Possible values: [Required, Ignored, Unwanted]
enumCommentRequirementRequiredEnum comments. Possible values: [Required, Ignored, Unwanted]
serialVersionUIDCommentRequiredIgnoredSerial version UID comments. Possible values: [Required, Ignored, Unwanted]
serialPersistentFieldsCommentRequiredIgnoredSerial persistent fields comments. Possible values: [Required, Ignored, Unwanted]

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

<ruleref="category/java/documentation.xml/CommentRequired"/>

Use this rule and customize it:

<ruleref="category/java/documentation.xml/CommentRequired"><properties><propertyname="methodWithOverrideCommentRequirement"value="Ignored"/><propertyname="accessorCommentRequirement"value="Ignored"/><propertyname="classCommentRequirement"value="Required"/><propertyname="fieldCommentRequirement"value="Required"/><propertyname="publicMethodCommentRequirement"value="Required"/><propertyname="protectedMethodCommentRequirement"value="Required"/><propertyname="enumCommentRequirement"value="Required"/><propertyname="serialVersionUIDCommentRequired"value="Ignored"/><propertyname="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:

NameDefault ValueDescription
maxLines6Maximum lines
maxLineLength80Maximum line length

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

<ruleref="category/java/documentation.xml/CommentSize"/>

Use this rule and customize it:

<ruleref="category/java/documentation.xml/CommentSize"><properties><propertyname="maxLines"value="6"/><propertyname="maxLineLength"value="80"/></properties></rule>

DanglingJavadoc

Since: PMD 7.17.0

Priority: Medium (3)

Javadoc comments that do not belong to a class, method or field are ignored by the JavaDoc tooland don’t end up in the generated API documentation. Such comments are either misplaced(e.g. between annotations and method declaration) or should be block comments.

In order to fix this violation, the comment should be moved to the correct place,converted into a block comment or removed completely.

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

Example(s):

publicclassFoo{/**   * Public methods // wrong   *//**   * A setter // OK   */publicvoidsetFoo(){}}

Use this rule by referencing it:

<ruleref="category/java/documentation.xml/DanglingJavadoc"/>

UncommentedEmptyConstructor

Since: PMD 3.4

Priority: Medium (3)

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

This rule is defined by the following XPath expression:

//ConstructorDeclaration[@Visibility!="private"][not(pmd-java:hasAnnotation('javax.inject.Inject')orpmd-java:hasAnnotation('org.springframework.beans.factory.annotation.Autowired'))][Block[@containsComment=false()and(count(*)=0or($ignoreExplicitConstructorInvocation=true()andcount(*)=1andExplicitConstructorInvocation))]]

Example(s):

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

This rule has the following properties:

NameDefault ValueDescription
ignoreExplicitConstructorInvocationfalseIgnore explicit constructor invocation when deciding whether constructor is empty or not

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

<ruleref="category/java/documentation.xml/UncommentedEmptyConstructor"/>

Use this rule and customize it:

<ruleref="category/java/documentation.xml/UncommentedEmptyConstructor"><properties><propertyname="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 containstatements, but there is no comment. By explicitly commenting empty method bodiesit is easier to distinguish between intentional (commented) and unintentionalempty methods.

This rule is defined by the following XPath expression:

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

Example(s):

publicvoiddoSomething(){}

Use this rule by referencing it:

<ruleref="category/java/documentation.xml/UncommentedEmptyMethodBody"/>

This documentation is written in markdown.
If there is something missing or can be improved, edit this page on github and create a PR: Edit on GitHub

©2025 PMD Open Source Project. All rights reserved.
Site last generated: Sep 12, 2025

PMD                logo


[8]ページ先頭

©2009-2025 Movatter.jp