Disallow Warning Comments (no-warning-comments)

Often code is marked during development process for later work on it or with additional thoughts. Examples are typically // TODO: do something or // FIXME: this is not a good idea. These comments are a warning signal, that there is something not production ready in your code. Most likely you want to fix it or remove the comments before you roll out your code with a good feeling.

Rule Details

This rule can be used to help finding these warning-comments. It can be configured with an array of terms you don’t want to exist in your code. It will raise a warning when one or more of the configured warning-comments are present in the checked files.

The default configuration looks like this:

"no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }]

This preconfigures

As already seen above, the configuration is quite simple. Example that enables the rule and configures it to check the complete comment, not only the start:

"no-warning-comments": [2, { "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }]

The following patterns are considered problems:

/*eslint no-warning-comments: [2, { "terms": ["todo", "fixme", "any other term"], "location": "anywhere" }]*/

// TODO: this                          /*error Unexpected 'todo' comment.*/
// todo: this too                      /*error Unexpected 'todo' comment.*/
// Even this: TODO                     /*error Unexpected 'todo' comment.*/
/*                                     /*error Unexpected 'todo' comment.*/ /*error Unexpected 'fixme' comment.*/ /*Unexpected 'any other term' comment.*/ /*
 * The same goes for this TODO comment
 * Or a fixme
 * as well as any other term
 */

These patterns would not be considered problems:

/*eslint no-warning-comments: [2, { "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
 */

Rule Options

"no-warning-comments": [<enabled>, { "terms": <terms>, "location": <location> }]

When Not To Use It

More examples of valid configurations

  1. Rule configured to warn on matches and search the complete comment, not only the start of it. Note that the term configuration is omitted to use the defaults terms.

    "no-warning-comments": [1, { "location": "anywhere" }]
    
  2. Rule configured to warn on matches of the term bad string at the start of comments. Note that the location configuration is omitted to use the default location.

    "no-warning-comments": [1, { "terms": ["bad string"] }]
    
  3. Rule configured to warn with error on matches of the default terms at the start of comments. Note that the complete configuration object (that normally holds terms and/or location) can be omitted for simplicity.

    "no-warning-comments": [2]
    
  4. Rule configured to warn on matches of the default terms at the start of comments. Note that the complete configuration object (as already seen in the example above) and even the square brackets can be omitted for simplicity.

    "no-warning-comments": 1
    
  5. Rule configured to warn on matches of the specified terms at any location in the comments. Note that you can use as many terms as you want.

    "no-warning-comments": [1, { "terms": ["really any", "term", "can be matched"], "location": "anywhere" }]
    

Version

This rule was introduced in ESLint 0.4.4.

Resources