DescendantTokenCheck with comments

9 views
Skip to first unread message

Googmeister

unread,
Jul 15, 2016, 12:58:18 PM7/15/16
to checkstyle
I would like to configure checkstyle to flag a class that has no comments. The DescendantToken check seems appropriate for the job (see xml file below) but it always reports finding no comments.

[Error] Total count of 0 is less than minimum count 1 under 'CLASS_DEF'. [DescendantToken]


I think DescendantTokenCheck.java is not exploring comment nodes because isCommentNodesRequired() is not overridden to return true. I'm using Checkstyle 6.19. Thanks for any advice!


------------------------------------

<?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">

    <module name="TreeWalker">


        <!--  at least 1 single-line comments  -->

        <module name="DescendantToken">

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

            <property name="limitedTokens" value="SINGLE_LINE_COMMENT, BLOCK_COMMENT_BEGIN"/>

            <property name="sumTokenCounts" value="true"/>

            <property name="minimumNumber" value="1"/>

        </module>


    </module>


</module>

Roman Ivanov

unread,
Jul 15, 2016, 11:09:07 PM7/15/16
to Googmeister, checkstyle
good point.


This Check does not override isCommentNodesRequired only because previously non of the Check had comments nodes. This method was introduced to provide support for new implementation of Checks for javadoc (commends based). 

DescendantToken should override this method and receive a tree with comment nodes. Please create an issue on this. Well known best practice that this will help to catch is  multiline comments inside methods (any BLOCK_COMMENT_BEGIN under OBJBLOCK).

Please put this use case a reason of such update to github issue, and you are welcome with Pull Request (do not forget to put that example in xdoc files , users like examples of usage)

---
Roman Ivanov
Reply all
Reply to author
Forward
0 new messages