TodoComment
Since Checkstyle 3.0
Description
TODO: comments. Actually it is a generic
pattern matcher on Java comments. To check for other patterns
in Java comments, set the format property.
Notes
Using TODO: comments is a great way to keep track of tasks that need to be done.
Having them reported by Checkstyle makes it very hard to forget about them.
Properties
Examples
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="TodoComment"/>
</module>
</module>
Example:
public class Example1 {
int i;
int x;
public void test() {
i++; // TODO: do differently in future // violation
i++; // todo: do differently in future
i=i/x; // FIXME: handle x = 0 case
i=i/x; // FIX : handle x = 0 case
}
}
To configure the check for comments that contain TODO and FIXME,
case-insensitive:
<module name="Checker">
<module name="TreeWalker">
<module name="TodoComment">
<property name="format" value="(?i)(TODO)|(FIXME)"/>
</module>
</module>
</module>
Example:
public class Example2 {
int i;
int x;
public void test() {
i++; // TODO: do differently in future // violation
i++; // todo: do differently in future // violation
i=i/x; // FIXME: handle x = 0 case // violation
i=i/x; // FIX : handle x = 0 case
}
}
To configure the check to detect box comments (Google Java Style Guide §4.8.6.3):
<module name="Checker">
<module name="TreeWalker">
<module name="TodoComment">
<property name="id" value="BoxComments"/>
<property name="format" value="^\s*([*=#-])\1{8,}\s*$"/>
<message key="todo.match"
value="Comment should not be enclosed in a box."/>
</module>
</module>
</module>
Example:
/** // violation 'Comment should not be enclosed in a box'
=========================================
Box comment with equals
=========================================
*/
public class Example3 {
// violation below 'Comment should not be enclosed in a box'
// ---------
void method1() {
int x = 1;
}
// violation below 'Comment should not be enclosed in a box'
// =========
void method2() {
int y = 2;
}
// violation below 'Comment should not be enclosed in a box'
// *********
void method3() {
int z = 3;
}
// violation below 'Comment should not be enclosed in a box'
// #########
void method4() {
int a = 4;
}
// normal comment
void method5() {
int b = 5;
}
// ###### (only 6 chars - below 9-char threshold)
void method6() {
int c = 6;
}
}
Example of Usage
Violation Messages
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
Package
com.puppycrawl.tools.checkstyle.checks






