Add reportMissingProperty property

This commit is contained in:
babula
2021-12-17 13:34:47 -05:00
parent 14303f2529
commit abfdb572d3
2 changed files with 43 additions and 7 deletions

View File

@ -48,10 +48,15 @@ public class ApexDocRule extends AbstractApexRule {
booleanProperty("reportMissingDescription")
.desc("Report missing @description").defaultValue(true).build();
private static final PropertyDescriptor<Boolean> REPORT_MISSING_PROPERTY_DESCRIPTOR =
booleanProperty("reportMissingProperty")
.desc("Report missing properties").defaultValue(true).build();
public ApexDocRule() {
definePropertyDescriptor(REPORT_PRIVATE_DESCRIPTOR);
definePropertyDescriptor(REPORT_PROTECTED_DESCRIPTOR);
definePropertyDescriptor(REPORT_MISSING_DESCRIPTION_DESCRIPTOR);
definePropertyDescriptor(REPORT_MISSING_PROPERTY_DESCRIPTOR);
addRuleChainVisit(ASTUserClass.class);
addRuleChainVisit(ASTUserInterface.class);
@ -113,13 +118,16 @@ public class ApexDocRule extends AbstractApexRule {
@Override
public Object visit(ASTProperty node, Object data) {
ApexDocComment comment = getApexDocComment(node);
if (comment == null) {
if (shouldHaveApexDocs(node)) {
addViolationWithMessage(data, node, MISSING_COMMENT_MESSAGE);
}
} else {
if (getProperty(REPORT_MISSING_DESCRIPTION_DESCRIPTOR) && !comment.hasDescription) {
addViolationWithMessage(data, node, MISSING_DESCRIPTION_MESSAGE);
if (getProperty(REPORT_MISSING_PROPERTY_DESCRIPTOR)) {
if (comment == null) {
if (shouldHaveApexDocs(node)) {
addViolationWithMessage(data, node, MISSING_COMMENT_MESSAGE);
}
} else {
if (getProperty(REPORT_MISSING_DESCRIPTION_DESCRIPTOR) && !comment.hasDescription) {
addViolationWithMessage(data, node, MISSING_DESCRIPTION_MESSAGE);
}
}
}

View File

@ -628,6 +628,34 @@ public class Foo {
*/
public Foo() {
}
}
]]></code>
</test-code>
<test-code>
<description>property should have comment</description>
<rule-property name="reportMissingProperty">true</rule-property>
<expected-problems>1</expected-problems>
<code><![CDATA[
/**
* @description Foo
*/
public class Foo {
global Object Bar { get; set; }
}
]]></code>
</test-code>
<test-code>
<description>property does not need comment</description>
<rule-property name="reportMissingProperty">false</rule-property>
<expected-problems>0</expected-problems>
<code><![CDATA[
/**
* @description Foo
*/
public class Foo {
global Object Bar { get; set; }
}
]]></code>
</test-code>