no-inline-comments

Disallow comments on the same line as code

A comment next to code makes the line longer, and it's easy to miss when you scan down the left edge of a file. With this rule, every comment goes on its own line.

Comments that configure the linter, such as // eslint-disable-line, aren't reported.

Configure#

Off by default. To turn it on:

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

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

bunfig.toml
[lint.rules]
"no-inline-comments" = ["error", {
  # ignorePattern = <string>,
}]

Examples#

example.js3 problems
const retries = 3; // the network is flaky
const timeout = /* seconds */ 30;
/* legacy */ connect(retries, timeout);
example.jsNo problems
// The network is flaky.
const retries = 3;

/* In seconds. */
const timeout = 30;

connect(retries, timeout); // eslint-disable-line no-undef

In JSX, a comment in braces is fine if nothing else shares a line with the braces:

example.jsxNo problems
const page = (
  <main>
    {/* The header comes from the layout. */}
    <Article />
  </main>
);
example.jsx1 problem
const page = (
  <main>
    <Article /> {/* The header comes from the layout. */}
  </main>
);

Options#

OptionDefaultWhat it does
ignorePatternnoneA regular expression. A comment whose text matches it isn't reported.
example.jswith { "ignorePattern": "webpackChunkName" }No problems
const locale = import(/* webpackChunkName: "locale-en" */ "./locale/en.js");
example.jswith { "ignorePattern": "webpackChunkName" }1 problem
const locale = import(/* the default */ "./locale/en.js");