Checkstyle TodoComment not detecting

124 views
Skip to first unread message

Shilpi Das

unread,
Jun 5, 2017, 3:05:42 AM6/5/17
to checkstyle-devel
Hello I wrote the below rule to check all the Todos and fixme commands

<module name="TodoComment">
<property name="format" value='(TODO)|(FIXME)|(TODO :)|(FIXME :)|(ToDo:)|
(FixMe:)|(ToDo :)|(FixMe :)|(Todo:)|(Fixme:)|(Todo :)|(Fixme :)|(todo:)|(fixme:)|
(todo :)|(fixme :)|(toDo:)|(fixMe:)|(toDo :)|(fixMe :)'
/>
<message key="todo.match" value="TODO/FIXME found. Your class cannot contain TODO/FIXME.
Please resolve." />
</module>

The problem is that it is not detecting
(FixMe:) , (todo :)


When I am writing the whole value portion in single line then it is detecting all the todos. I want to know the reason why this is happening.
And can I do anything so as to break the line. (I tried using || but it was not working)

R Veach

unread,
Jun 5, 2017, 10:23:53 AM6/5/17
to checkstyle-devel
It is most likely because you are not escaping the parenthesis if you expect users to use them in the code.
See the following example:

````
$ cat TestClass.java
public class TestClass {
    void method() {
// (FixMe:) , (todo :)
    }
}

$ 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="TodoComment">
    <property name="format" value='\(FixMe:\)' />

    <message key="todo.match" value="TODO/FIXME found. Your class cannot contain TODO/FIXME.
                Please resolve." />
</module>
    </module>
</module>

$ java -jar checkstyle-7.8.1-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:3: TODO/FIXME found. Your class cannot contain TODO/FIXME.                Please resolve. [TodoComment]
Audit done.
Checkstyle ends with 1 errors.
````

As a side note, instead of writing every case possible for the words, you can use `[Tt]` to handle both cases and hopefully make your expression simpler to read/maintain.


Shilpi Das

unread,
Jun 5, 2017, 9:57:17 PM6/5/17
to R Veach, checkstyle-devel
Thank you so much. It solved my problem

--
You received this message because you are subscribed to a topic in the Google Groups "checkstyle-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/checkstyle-devel/Pg_A8L5VebM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to checkstyle-devel+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages