CheckStyle doesn't flag missing JavaDoc on Interface Methods

gene b. :

Does anyone know why CheckStyle doesn't flag missing JavaDoc on Interface Methods, only on actual implementing methods?

Suppose I have the following,

<module name="JavadocMethod">
    <property name="scope" value="public"/>
    <property name="allowMissingParamTags" value="true"/>
    <property name="allowMissingThrowsTags" value="true"/>
    <property name="allowMissingReturnTag" value="true"/>
    <property name="minLineCount" value="2"/>
    <property name="allowedAnnotations" value="Override, Test"/>
    <property name="allowThrowsTagsForSubclasses" value="true"/>

This will report missing JavaDoc in actual class method, but not in Interface methods.

Also tried adding this, didn't work:

<property name="tokens" value="INTERFACE_DEF"/>
<property name="tokens" value="INTERFACE_DEF, CLASS_DEF"/>

Similiar thread that I got this from (but not working): checkstyle JavadocType only on interfaces

Any way to force the JavadocMethod check on Interface Methods?

Reason: Spring Data, the JPA library, is based on Interface-only method names where implementation is provided behind the scenes based on @Query annotation configurators. Thus we have no implementations of our own. So we need to check and require JavaDoc on Interface methods in this case.

rveach :

<property name="minLineCount" value="2"/>

This is why. You specify a javadoc is needed if line count is 2 or greater. Interfaces don't have any line counts, so that is why you aren't getting any violations.

$ cat TestClass.java
public interface TestInterface {
    void method();
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
<module name="JavadocMethod">
    <property name="scope" value="public"/>
    <property name="allowMissingParamTags" value="true"/>
    <property name="allowMissingThrowsTags" value="true"/>
    <property name="allowMissingReturnTag" value="true"/>
    <property name="allowedAnnotations" value="Override, Test"/>
    <property name="allowThrowsTagsForSubclasses" value="true"/>
</module>
    </module>
</module>

$ java -jar checkstyle-8.18-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:2:5: Missing a Javadoc comment. [JavadocMethod]
Audit done.
Checkstyle ends with 1 errors.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=96800&siteId=1