diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/documentation/ApexDocRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/documentation/ApexDocRule.java index 441693eee0..13aecd1ff7 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/documentation/ApexDocRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/documentation/ApexDocRule.java @@ -44,9 +44,14 @@ public class ApexDocRule extends AbstractApexRule { booleanProperty("reportProtected") .desc("Report protected methods").defaultValue(false).build(); + private static final PropertyDescriptor REPORT_MISSING_DESCRIPTION_DESCRIPTOR = + booleanProperty("reportMissingDescription") + .desc("Report missing @description").defaultValue(true).build(); + public ApexDocRule() { definePropertyDescriptor(REPORT_PRIVATE_DESCRIPTOR); definePropertyDescriptor(REPORT_PROTECTED_DESCRIPTOR); + definePropertyDescriptor(REPORT_MISSING_DESCRIPTION_DESCRIPTOR); addRuleChainVisit(ASTUserClass.class); addRuleChainVisit(ASTUserInterface.class); @@ -79,7 +84,7 @@ public class ApexDocRule extends AbstractApexRule { addViolationWithMessage(data, node, MISSING_COMMENT_MESSAGE); } } else { - if (!comment.hasDescription) { + if (getProperty(REPORT_MISSING_DESCRIPTION_DESCRIPTOR) && !comment.hasDescription) { addViolationWithMessage(data, node, MISSING_DESCRIPTION_MESSAGE); } @@ -113,7 +118,7 @@ public class ApexDocRule extends AbstractApexRule { addViolationWithMessage(data, node, MISSING_COMMENT_MESSAGE); } } else { - if (!comment.hasDescription) { + if (getProperty(REPORT_MISSING_DESCRIPTION_DESCRIPTOR) && !comment.hasDescription) { addViolationWithMessage(data, node, MISSING_DESCRIPTION_MESSAGE); } } @@ -128,7 +133,7 @@ public class ApexDocRule extends AbstractApexRule { addViolationWithMessage(data, node, MISSING_COMMENT_MESSAGE); } } else { - if (!comment.hasDescription) { + if (getProperty(REPORT_MISSING_DESCRIPTION_DESCRIPTOR) && !comment.hasDescription) { addViolationWithMessage(data, node, MISSING_DESCRIPTION_MESSAGE); } } diff --git a/pmd-apex/src/main/resources/category/apex/documentation.xml b/pmd-apex/src/main/resources/category/apex/documentation.xml index 5699ab1dff..de9ffc875a 100644 --- a/pmd-apex/src/main/resources/category/apex/documentation.xml +++ b/pmd-apex/src/main/resources/category/apex/documentation.xml @@ -22,7 +22,7 @@ This rule validates that: overrides and test classes (as well as the contents of test classes). * ApexDoc comments are present for classes, methods, and properties that are protected or private, depending on the properties `reportPrivate` and `reportProtected`. -* ApexDoc comments should contain @description. +* ApexDoc comments should contain @description depending on the property 'reportMissingDescription'. * ApexDoc comments on non-void, non-constructor methods should contain @return. * ApexDoc comments on void or constructor methods should not contain @return. * ApexDoc comments on methods with parameters should contain @param for each parameter, in the same diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/documentation/xml/ApexDoc.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/documentation/xml/ApexDoc.xml index 0bd349a322..76a010069f 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/documentation/xml/ApexDoc.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/documentation/xml/ApexDoc.xml @@ -571,6 +571,63 @@ public class Foo { public class Bar { } +} + ]]> + + + + #3566 [apex] ApexDoc: Verify use of reportMissingDescription, negative test unspecified/default + + 2 + + + + + #3566 [apex] ApexDoc: Verify use of reportMissingDescription, negative test specified + true + 2 + + + + + #3566 [apex] ApexDoc: Verify use of reportMissingDescription, positive test + false + 0 +