no-warning-comments
Disallow specified warning terms in comments
Developers often add comments to code which is not complete or needs review. Most likely you want to fix or review the code, and then remove the comment, before you consider the code to be production ready.
// TODO: do something
// FIXME: this is not a good idea
Rule Details
This rule reports comments that include any of the predefined terms specified in its configuration.
Options
This rule has an options object literal:
"terms"
: optional array of terms to match. Defaults to["todo", "fixme", "xxx"]
. Terms are matched case-insensitively and as whole words:fix
would matchFIX
but notfixing
. Terms can consist of multiple words:really bad idea
."location"
: optional string that configures where in your comments to check for matches. Defaults to"start"
. The start is from the first non-decorative character, ignoring whitespace, new lines and characters specified indecoration
. The other value is matchanywhere
in comments."decoration"
: optional array of characters that are ignored at the start of a comment, when location is"start"
. Defaults to[]
. Any sequence of whitespace or the characters from this property are ignored. This option is ignored when location is"anywhere"
.
Example of incorrect code for the default { "terms": ["todo", "fixme", "xxx"], "location": "start" }
options:
/*eslint no-warning-comments: "error"*/
function callback(err, results) {
if (err) {
console.error(err);
return;
}
}
Example of correct code for the default { "terms": ["todo", "fixme", "xxx"], "location": "start" }
options:
/*eslint no-warning-comments: "error"*/
function callback(err, results) {
if (err) {
console.error(err);
return;
}
// NOT READY FOR PRIME TIME
// but too bad, it is not a predefined warning term
}
terms and location
Examples of incorrect code for the { "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }
options:
/*eslint no-warning-comments: ["error", { "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }]*/
Examples of correct code for the { "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }
options:
/*eslint no-warning-comments: ["error", { "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }]*/
// This is to do
// even not any other term
// any other terminal
/*
* The same goes for block comments
* with any other interesting term
* or fix me this
*/
Decoration Characters
Examples of incorrect code for the { "decoration": ["*"] }
options:
/*eslint no-warning-comments: ["error", { "decoration": ["*"] }]*/
Examples of incorrect code for the { "decoration": ["/", "*"] }
options:
/*eslint no-warning-comments: ["error", { "decoration": ["/", "*"] }]*/
Examples of correct code for the { "decoration": ["/", "*"] }
options:
/*eslint no-warning-comments: ["error", { "decoration": ["/", "*"] }]*/
//!TODO preceded by non-decoration character
/**
*!TODO preceded by non-decoration character in a block comment
*/
When Not To Use It
- If you have a large code base that was not developed with a policy to not use such warning terms, you might get hundreds of warnings / errors which might be counter-productive if you can’t fix all of them (e.g. if you don’t get the time to do it) as you might overlook other warnings / errors or get used to many of them and don’t pay attention on it anymore.
- Same reason as the point above: You shouldn’t configure terms that are used very often (e.g. central parts of the native language used in your comments).
Version
This rule was introduced in ESLint v0.4.4.