Disallow inline comments after code
Some style guides disallow comments on the same line as code. Code can become difficult to read if comments immediately follow the code on the same line. On the other hand, it is sometimes faster and more obvious to put comments immediately following code.
This rule disallows comments on the same line as code.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Comments inside the curly braces in JSX are allowed to be on the same line as the braces, but only if they are not on the same line with other code, and the braces do not enclose an actual expression.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
/*eslint no-inline-comments: "error"*/
var foo = (
<div>
{/* These braces are just for this comment and there is nothing else on this line */}
<h1>Some heading</h1>
</div>
)
var bar = (
<div>
{
// There is nothing else on this line
baz
}
</div>
);
var quux = (
<div>
{/*
Multiline
comment
*/}
<h1>Some heading</h1>
</div>
)
To make this rule ignore specific comments, set the ignorePattern
option to a string pattern that will be passed to the RegExp
constructor.
Examples of correct code for the ignorePattern
option:
Examples of incorrect code for the ignorePattern
option:
This rule was introduced in ESLint v0.10.0.
© OpenJS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/latest/rules/no-inline-comments