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 flakyUnexpected comment inline with code.
const timeout = /* seconds */Unexpected comment inline with code. 30;
/* legacy */Unexpected comment inline with code. 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-undefIn 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. */Unexpected comment inline with code.}
</main>
);Options#
| Option | Default | What it does |
|---|---|---|
ignorePattern | none | A regular expression. A comment whose text matches it isn't reported. |
example.jswith
{ "ignorePattern": "webpackChunkName" }No problemsconst locale = import(/* webpackChunkName: "locale-en" */ "./locale/en.js");example.jswith
{ "ignorePattern": "webpackChunkName" }1 problemconst locale = import(/* the default */Unexpected comment inline with code. "./locale/en.js");