Skip to content
โ† Back to rules

eslint/capitalized-comments Style

๐Ÿ› ๏ธ An auto-fix is available for this rule.

What it does โ€‹

Enforces or disallows capitalization of the first letter of a comment.

Why is this bad? โ€‹

Inconsistent capitalization of comments can make code harder to read. This rule helps enforce a consistent style across the codebase.

Examples โ€‹

Examples of incorrect code for this rule with the default "always" option:

js
// lowercase comment
/* lowercase block comment */

Examples of correct code for this rule with the default "always" option:

js
// Capitalized comment
/* Capitalized block comment */
// 123 - comments starting with non-letters are ignored

Configuration โ€‹

Configuration for the capitalized-comments rule.

The first element specifies whether comments should "always" or "never" begin with a capital letter. The second element is an optional object containing additional options.

The 1st option โ€‹

type: "always" | "never"

The 2nd option โ€‹

This option is an object with the following properties:

block โ€‹

type: object

Configuration options specific to block comments.

block.ignoreConsecutiveComments โ€‹

type: boolean

If true, consecutive comments will be ignored after the first comment.

block.ignoreInlineComments โ€‹

type: boolean

If true, inline comments (comments in the middle of code) will be ignored.

block.ignorePattern โ€‹

type: string

A regex pattern. Comments that match the pattern will not cause violations.

ignoreConsecutiveComments โ€‹

type: boolean

If true, consecutive comments will be ignored after the first comment.

ignoreInlineComments โ€‹

type: boolean

If true, inline comments (comments in the middle of code) will be ignored.

ignorePattern โ€‹

type: string

A regex pattern. Comments that match the pattern will not cause violations.

line โ€‹

type: object

Configuration options specific to line comments.

line.ignoreConsecutiveComments โ€‹

type: boolean

If true, consecutive comments will be ignored after the first comment.

line.ignoreInlineComments โ€‹

type: boolean

If true, inline comments (comments in the middle of code) will be ignored.

line.ignorePattern โ€‹

type: string

A regex pattern. Comments that match the pattern will not cause violations.

How to use โ€‹

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "capitalized-comments": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "capitalized-comments": "error",
  },
});
bash
oxlint --deny capitalized-comments

Version โ€‹

This rule was added in v1.34.0.

References โ€‹