capitalized-comments

Require comments to start with a capital letter, or forbid it

fixable

This is a style rule that makes every comment start the same way. By default, a comment that starts with a lowercase letter is reported.

Comments that start with something other than a letter, comments that start with a URL, and comments for tools such as eslint-disable, global or istanbul ignore are never reported.

--fix changes the case of the first letter.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"capitalized-comments" = "error" # or "warn"

Every option, set to its default. The ones that are commented out are unset by default.

bunfig.toml
[lint.rules]
"capitalized-comments" = [
  "error",
  "always", # "always" or "never"
  {
    # ignorePattern = <string>,
    ignoreInlineComments = false,
    ignoreConsecutiveComments = false,
    # line = <object>,
    # block = <object>,
  },
]

Examples#

example.js1 problem
// retry once, then give up
await send(message);
example.jsNo problems
// Retry once, then give up
await send(message);

// 3 attempts at most
// https://example.com/retries explains why
/* eslint-disable-next-line no-console */
console.log("sent");

Options#

bunfig.toml
[lint.rules]
capitalized-comments = ["error", "always", { ignoreConsecutiveComments = true }]

The first option is "always" (default), which requires a capital letter, or "never", which requires a lowercase letter.

example.jswith "never"1 problem
// Retry once, then give up
await send(message);

The second option is an object:

OptionDefaultWhat it does
ignorePatternnoneA regular expression. A comment that starts with a match isn't checked.
ignoreInlineCommentsfalseDon't check a comment that has code before and after it on the same line.
ignoreConsecutiveCommentsfalseDon't check a comment that comes right after another comment, so only the first line of a group counts.
example.jswith "always", { "ignorePattern": "webpack" }No problems
const editor = import(/* webpackChunkName: "editor" */ "./editor.js");
example.jswith "always", { "ignoreInlineComments": true }No problems
function resize(width, /* optional */ height) {}
example.jswith "always", { "ignoreConsecutiveComments": true }No problems
// Retry once, then give up,
// so that a slow server does not block the queue
await send(message);

To use different settings for // and /* */ comments, put the same options under line and block. Here only the // comment is reported:

example.jswith "always", { "block": { "ignorePattern": "webpack" } }1 problem
// webpack splits the bundle here
const editor = import(/* webpackChunkName: "editor" */ "./editor.js");