]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/lines-between-class-members.md
27084c28346f431bd3a496f26ffb72184637c342
[pve-eslint.git] / eslint / docs / rules / lines-between-class-members.md
1 # require or disallow an empty line between class members (lines-between-class-members)
2
3 This rule improves readability by enforcing lines between class members. It will not check empty lines before the first member and after the last member, since that is already taken care of by padded-blocks.
4
5 ## Rule Details
6
7 Examples of **incorrect** code for this rule:
8
9 ```js
10 /* eslint lines-between-class-members: ["error", "always"]*/
11 class MyClass {
12 x;
13 foo() {
14 //...
15 }
16 bar() {
17 //...
18 }
19 }
20 ```
21
22 Examples of **correct** code for this rule:
23
24 ```js
25 /* eslint lines-between-class-members: ["error", "always"]*/
26 class MyClass {
27 x;
28
29 foo() {
30 //...
31 }
32
33 bar() {
34 //...
35 }
36 }
37 ```
38
39 Examples of additional **correct** code for this rule:
40
41 ```js
42 /* eslint lines-between-class-members: ["error", "always"]*/
43 class MyClass {
44 x = 1
45
46 ;in = 2
47 }
48 ```
49
50 ### Options
51
52 This rule has a string option and an object option.
53
54 String option:
55
56 * `"always"`(default) require an empty line after class members
57 * `"never"` disallows an empty line after class members
58
59 Object option:
60
61 * `"exceptAfterSingleLine": false`(default) **do not** skip checking empty lines after single-line class members
62 * `"exceptAfterSingleLine": true` skip checking empty lines after single-line class members
63
64 Examples of **incorrect** code for this rule with the string option:
65
66 ```js
67 /* eslint lines-between-class-members: ["error", "always"]*/
68 class Foo{
69 x;
70 bar(){}
71 baz(){}
72 }
73
74 /* eslint lines-between-class-members: ["error", "never"]*/
75 class Foo{
76 x;
77
78 bar(){}
79
80 baz(){}
81 }
82 ```
83
84 Examples of **correct** code for this rule with the string option:
85
86 ```js
87 /* eslint lines-between-class-members: ["error", "always"]*/
88 class Foo{
89 x;
90
91 bar(){}
92
93 baz(){}
94 }
95
96 /* eslint lines-between-class-members: ["error", "never"]*/
97 class Foo{
98 x;
99 bar(){}
100 baz(){}
101 }
102 ```
103
104 Examples of **correct** code for this rule with the object option:
105
106 ```js
107 /* eslint lines-between-class-members: ["error", "always", { "exceptAfterSingleLine": true }]*/
108 class Foo{
109 x; // single line class member
110 bar(){} // single line class member
111 baz(){
112 // multi line class member
113 }
114
115 qux(){}
116 }
117 ```
118
119 ## When Not To Use It
120
121 If you don't want to enforce empty lines between class members, you can disable this rule.
122
123 ## Related Rules
124
125 * [padded-blocks](padded-blocks.md)
126 * [padding-line-between-statements](padding-line-between-statements.md)
127
128 ## Compatibility
129
130 * [requirePaddingNewLinesAfterBlocks](https://jscs-dev.github.io/rule/requirePaddingNewLinesAfterBlocks)
131 * [disallowPaddingNewLinesAfterBlocks](https://jscs-dev.github.io/rule/disallowPaddingNewLinesAfterBlocks)