Search code examples
maven-2commentsdesign-patternsjavadoccheckstyle

How can I make mvn checkstyle check if all my javadoc comment's contents start with an uppercase?


I'd like to have my checkstyle configured so that it verifies all my javadoc comments start with an upper case letter:

/** 
 * Hello

Where can I set that up? I think I'll have to enable checkstyle on comments first but I'm not sure how.

And then how do I set up a filter that checks for the occurence of \/\*\* and then ensures a \s*\*\s[A-Z]+ follows?

EDIT: If What I need is not supported by checkstyle at the moment: How do I set up my own checkstyle modul and include it?


Solution

  • Currently, Checkstyle does not support what you want to get (as I know). But the process to do that should be the following:

    • Add the checkstyle maven plugin org.apache.maven.plugins:maven-checkstyle-plugin to your Maven2 POM.
    • Create a checkstyle configuration that includes the rules that you want to have.
    • Reference that configuration in your POM as configLocation.

    Checkstyle supports as rules for classes and style:

    • Check empty JavaDoc
    • Check first sentence (that it exist)
    • Check end of sentence (but not begin)

    What you can do (in the long run) is to expand checkstyle, and to give your enhancement to the community, so it may be integrated into Checkstyle itself and the Maven plugin for Checkstyle. Have a look at "Extending Checkstyle", it is not so difficult, I have done that on my own. See for an example the implementation of Checkstyle JavaDoc Style. The difficult part is to put that in the project, and get it everywhere you will need it: Maven, Eclipse, NetBeans, Sonar, ...