Checkstyle: JavadocStyle: check if javadoc starts with an uppercase letter

Created on 26 Sep 2016  路  5Comments  路  Source: checkstyle/checkstyle

I would like a new feature in JavadocStyle where it checks that if the first word of the JavaDoc starts with a letter, it is capitalized.
This check already verifies if the JavaDoc contains a period of some kind. Periods ensures that it is a sentence, and in most languages, proper sentences usually start with an uppercase letter.

$ cat TestClass.java
public class TestClass {
    /** this is a method. */
    void method1() {}
    /** 101 leagues under the sea. */
    void method2() {}
    /** <b>this is a method.</b> */
    void method3() {}
}

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

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

    <module name="TreeWalker">
<module name="JavadocStyle" />
    </module>
</module>

$ java -jar checkstyle-7.1.1-all.jar -c TestConfig.xml TestClass.java
Starting audit...
Audit done.

I expect violations on method1 and method3 because the first word of the sentence, this, is not capitalized. There should be no violations if the user wrote This in the JavaDoc.
method2 has no violation because it's first word 101 doesn't start with a letter.

javadoc

Most helpful comment

Any news about this feature ? Or a workaround ?

All 5 comments

I am on it

@kukreja-vikramaditya This issue doesn't have approved label on it, so it can't be worked on until then.

Should this new property be able to check for character inside a tag? <- thought for future idea


Javadoc 1
```java
/** hello */

Javadoc 2
```java
/**
 * <pre>
 * class Foo {
 *
 *   void foo() {}
 * }
 * </pre>
 */

Is it possible to differentiate between the 2 with some sort of javadoc token detector? What if user has custom tags?

Should this new property be able to check for character inside a tag?

IMO, as long as it is part of the first sentence of the javadoc description, it should validate that text inside.
We should use javadoc utility to confirm all tags and first sentences.

These are my thoughts:
<b> - Bolding/underlining/etc is just to make text flashy, First sentence is inside tag and should still be validated.
<pre> - To me, pre shouldn't be considered part of first sentence. It is code to me.
<p> - Same as bolding, first text is inside.
<table> - Same as pre.
<ul> - Same as pre.

Is it possible to differentiate between the 2 with some sort of javadoc token detector?

Using the Javadoc tree, yes. I doubt the regular expression version of the check could do this.

What if user has custom tags?

Must see how javadoc utility handles it, then we could decide.

Any news about this feature ? Or a workaround ?

Was this page helpful?
0 / 5 - 0 ratings