enforce or disallow capitalization of the first letter of a comment (capitalized-comments)

The --fix option on the command line can automatically fix some of the problems reported by this rule.

Comments are useful for leaving information for future developers. In order for that information to be useful and not distracting, it is sometimes desirable for comments to follow a particular style. One element of comment formatting styles is whether the first word of a comment should be capitalized or lowercase.

In general, no comment style is any more or less valid than any others, but many developers would agree that a consistent style can improve a project’s maintainability.

Rule Details

This rule aims to enforce a consistent style of comments across your codebase, specifically by either requiring or disallowing a capitalized letter as the first word character in a comment. This rule will not issue warnings when non-cased letters are used.

By default, this rule will require a non-lowercase letter at the beginning of comments.

Options

This rule has two options: a string value "always" or "never" which determines whether capitalization of the first word of a comment should be required or forbidden, and optionally an object containing more configuration parameters for the rule.

Here are the supported object options:

ignorePattern: A string representing a regular expression pattern of words that should be ignored by this rule. If the first word of a comment matches the pattern, this rule will not report that comment.

Note that the following words are always ignored by this rule: ["jscs", "jshint", "eslint", "istanbul", "global", "globals", "exported"].

ignoreInlineComments: If this is true, the rule will not report on comments in the middle of code. By default, this is false.

ignoreConsecutiveComments: If this is true, the rule will not report on a comment which violates the rule, as long as the comment immediately follows another comment. By default, this is false.

ignoreInlineComments

Setting the ignoreInlineComments option to true means that comments in the middle of code (with a token on the same line as the beginning of the comment, and another token on the same line as the end of the comment) will not be reported by this rule.

Examples of correct code with the "ignoreInlineComments" option set to true:

ignoreConsecutiveComments

If the ignoreConsecutiveComments option is set to true, then comments which otherwise violate the rule will not be reported as long as they immediately follow another comment. This can be applied more than once.

Examples of correct code with ignoreConsecutiveComments set to true:

/* eslint capitalize-comments: ["error", "always", { "ignoreConsecutiveComments": true }] */// This comment is valid since it has the correct capitalization.// this comment is ignored since it follows another comment,// and this one as well because it follows yet another comment./* Here is a block comment which has the correct capitalization, *//* but this one is ignored due to being consecutive; *//*
* in fact, even if any of these are multi-line, that is fine too.
*/

Examples of incorrect code with ignoreConsecutiveComments set to true:

/* eslint capitalize-comments: ["error", "always", { "ignoreConsecutiveComments": true }] */// this comment is invalid, but only on this line.// this comment does NOT get reported, since it is a consecutive comment.

Using Different Options for Line and Block Comments

If you wish to have a different configuration for line comments and block comments, you can do so by using two different object configurations (note that the capitalization option will be enforced consistently for line and block comments):