Search code examples
javacheckstyleintellij-pluginmaven-checkstyle-plugin

How to restrict the @parma of javadoc to have comments in checkstyle


How to restrict the @parma of javadoc to have comments in checkstyle

such as

/**
 * text
 * @param args  //Error reported here, must have comment
 */
public static void main(String[] args) {}

Solution

  • Use NonEmptyAtclauseDescription, https://checkstyle.org/config_javadoc.html#NonEmptyAtclauseDescription

    $ cat TestClass.java
    public class TestClass {
        /**
         * text.
         * @param args
         */
        public static void main(String[] args) {}
    }
    
    $ 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="NonEmptyAtclauseDescription"/>
        </module>
    </module>
    
    $ java -jar checkstyle-10.1-all.jar -c TestConfig.xml TestClass.java
    Starting audit...
    [ERROR] TestClass.java:4: At-clause should have a non-empty description. [NonEmptyAtclauseDescription]
    Audit done.
    Checkstyle ends with 1 errors.