1 # disallow inline comments after code (no-inline-comments)
3 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.
4 On the other hand, it is sometimes faster and more obvious to put comments immediately following code.
8 This rule disallows comments on the same line as code.
10 Examples of **incorrect** code for this rule:
13 /*eslint no-inline-comments: "error"*/
15 var a = 1; // declaring a to 1
17 function getRandomNumber(){
18 return 4; // chosen by fair dice roll.
19 // guaranteed to be random.
22 /* A block comment before code */ var b = 2;
24 var c = 3; /* A block comment after code */
27 Examples of **correct** code for this rule:
30 /*eslint no-inline-comments: "error"*/
32 // This is a comment above a line of code
36 //This is a comment below a line of code
41 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.
43 Examples of **incorrect** code for this rule:
46 /*eslint no-inline-comments: "error"*/
48 var foo = <div>{ /* On the same line with other code */ }<h1>Some heading</h1></div>;
52 { // These braces are not just for the comment, so it can't be on the same line
59 Examples of **correct** code for this rule:
62 /*eslint no-inline-comments: "error"*/
66 {/* These braces are just for this comment and there is nothing else on this line */}
74 // There is nothing else on this line