Skip to main content

format-line-comments

Disallows // comments longer than N characters and multi-line comments that can be merged together.

Like Prettier, this rule is designed to auto-format your comments so that you don't have to think about it. Try configuring your IDE to run eslint --fix on save.

Also see the format-jsdoc-comments rule.

For more information on why you should use this rule, see the comment formatting discussion.

Rule Details

Lines that are too long will be split to the next line:

// Bad
// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

// Good
// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
// labore et dolore magna aliqua.

Lines that are too short will be merged together:

// Bad
// Lorem ipsum dolor sit amet,
// consectetur adipiscing elit

// Good
// Lorem ipsum dolor sit amet, consectetur adipiscing elit

The rule tries to be as smart as possible. For example, it won't complain about TypeScript triple slash directives:

/// <reference path="foo1.d.ts" />

You can open a GitHub issue if you find a situation where this rule should be smarter.

Options and Defaults

{
"rules": {
"complete/format-line-comments": [
"error",
{
"maxLength": 100
}
]
}
}

Resources