]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/no-inline-comments.md
cde77e9e49914e852ede3ab9e50a58e937081398
[pve-eslint.git] / eslint / docs / rules / no-inline-comments.md
1 # disallow inline comments after code (no-inline-comments)
2
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.
5
6 ## Rule Details
7
8 This rule disallows comments on the same line as code.
9
10 Examples of **incorrect** code for this rule:
11
12 ```js
13 /*eslint no-inline-comments: "error"*/
14
15 var a = 1; // declaring a to 1
16
17 function getRandomNumber(){
18 return 4; // chosen by fair dice roll.
19 // guaranteed to be random.
20 }
21
22 /* A block comment before code */ var b = 2;
23
24 var c = 3; /* A block comment after code */
25 ```
26
27 Examples of **correct** code for this rule:
28
29 ```js
30 /*eslint no-inline-comments: "error"*/
31
32 // This is a comment above a line of code
33 var foo = 5;
34
35 var bar = 5;
36 //This is a comment below a line of code
37 ```
38
39 ### JSX exception
40
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.
42
43 Examples of **incorrect** code for this rule:
44
45 ```js
46 /*eslint no-inline-comments: "error"*/
47
48 var foo = <div>{ /* On the same line with other code */ }<h1>Some heading</h1></div>;
49
50 var bar = (
51 <div>
52 { // These braces are not just for the comment, so it can't be on the same line
53 baz
54 }
55 </div>
56 );
57 ```
58
59 Examples of **correct** code for this rule:
60
61 ```js
62 /*eslint no-inline-comments: "error"*/
63
64 var foo = (
65 <div>
66 {/* These braces are just for this comment and there is nothing else on this line */}
67 <h1>Some heading</h1>
68 </div>
69 )
70
71 var bar = (
72 <div>
73 {
74 // There is nothing else on this line
75 baz
76 }
77 </div>
78 );
79
80 var quux = (
81 <div>
82 {/*
83 Multiline
84 comment
85 */}
86 <h1>Some heading</h1>
87 </div>
88 )
89 ```