You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check parentheses with new lines for multiline JSX
This changes the options from a boolean to an enum with three possible
values: `ignore`, `parens`, and `parens-new-line`. Using `ignore` is like
the previous `false` while `parens` is like the previous `true`. The new
option (`parens-new-line`) will check that the parentheses around the
multiline JSX are on separate lines for better readability.
@@ -6,16 +6,20 @@ Wrapping multiline JSX in parentheses can improve readability and/or convenience
6
6
7
7
## Rule Details
8
8
9
-
This rule optionally takes a second parameter in the form of an object, containing places to apply the rule. By default, all the syntax listed below will be checked, but these can be explicitly disabled. Any syntax type missing in the object will follow the default behavior (become enabled).
9
+
This rule optionally takes a second parameter in the form of an object, containing places to apply the rule. The four possible keys are `declaration`, `assignment`, `return`, and `arrow`. The three possible values are `ignore`, `parens`, and `parens-new-line`. By default, all the syntax listed below will be checked with the `parens` option, but these can be explicitly changed. Any syntax type missing in the object will follow the default behavior (`parens`).
10
10
11
-
There are the possible syntax available:
11
+
The default values are:
12
12
13
-
*`declaration`
14
-
*`assignment`
15
-
*`return`
16
-
*`arrow`
13
+
```json
14
+
{
15
+
"declaration": "parens",
16
+
"assignment": "parens",
17
+
"return": "parens",
18
+
"arrow": "parens"
19
+
}
20
+
```
17
21
18
-
The following patterns are considered warnings:
22
+
The following patterns are considered warnings when using `parens` or `parens-new-line`:
19
23
20
24
```jsx
21
25
var Hello =createReactClass({
@@ -27,6 +31,18 @@ var Hello = createReactClass({
27
31
});
28
32
```
29
33
34
+
The following patterns are considered warnings when using `parens-new-line`:
35
+
36
+
```jsx
37
+
var Hello =createReactClass({
38
+
render:function() {
39
+
return (<div>
40
+
<p>Hello {this.props.name}</p>
41
+
</div>);
42
+
}
43
+
});
44
+
```
45
+
30
46
The following patterns are not considered warnings:
31
47
32
48
```jsx
@@ -43,15 +59,17 @@ var Hello = createReactClass({
43
59
});
44
60
```
45
61
46
-
The following patterns are considered warnings when configured `{declaration: true}`.
62
+
### `declaration`
63
+
64
+
The following patterns are considered warnings when configured `{declaration: "parens"}`.
47
65
48
66
```jsx
49
67
var hello =<div>
50
68
<p>Hello</p>
51
69
</div>;
52
70
```
53
71
54
-
The following patterns are not considered warnings when configured `{declaration: true}`.
72
+
The following patterns are not considered warnings when configured `{declaration: "parens"}`.
55
73
56
74
```jsx
57
75
var hello = (
@@ -61,7 +79,39 @@ var hello = (
61
79
);
62
80
```
63
81
64
-
The following patterns are considered warnings when configured `{assignment: true}`.
82
+
```jsx
83
+
var hello = (<div>
84
+
<p>Hello</p>
85
+
</div>);
86
+
```
87
+
88
+
The following patterns are considered warnings when configured `{declaration: "parens-new-line"}`.
89
+
90
+
```jsx
91
+
var hello =<div>
92
+
<p>Hello</p>
93
+
</div>;
94
+
```
95
+
96
+
```jsx
97
+
var hello = (<div>
98
+
<p>Hello</p>
99
+
</div>);
100
+
```
101
+
102
+
The following patterns are not considered warnings when configured `{declaration: "parens-new-line"}`.
103
+
104
+
```jsx
105
+
var hello = (
106
+
<div>
107
+
<p>Hello</p>
108
+
</div>
109
+
);
110
+
```
111
+
112
+
### `assignment`
113
+
114
+
The following patterns are considered warnings when configured `{assignment: "parens"}`.
65
115
66
116
```jsx
67
117
var hello;
@@ -70,7 +120,7 @@ hello = <div>
70
120
</div>;
71
121
```
72
122
73
-
The following patterns are not considered warnings when configured `{assignment: true}`.
123
+
The following patterns are not considered warnings when configured `{assignment: "parens"}`.
74
124
75
125
```jsx
76
126
var hello;
@@ -80,7 +130,44 @@ hello = (
80
130
</div>
81
131
);
82
132
```
83
-
The following patterns are considered warnings when configured `{return: true}`.
133
+
134
+
```jsx
135
+
var hello;
136
+
hello = (<div>
137
+
<p>Hello</p>
138
+
</div>);
139
+
```
140
+
141
+
The following patterns are considered warnings when configured `{assignment: "parens-new-line"}`.
142
+
143
+
```jsx
144
+
var hello;
145
+
hello =<div>
146
+
<p>Hello</p>
147
+
</div>;
148
+
```
149
+
150
+
```jsx
151
+
var hello;
152
+
hello = (<div>
153
+
<p>Hello</p>
154
+
</div>);
155
+
```
156
+
157
+
The following patterns are not considered warnings when configured `{assignment: "parens-new-line"}`.
158
+
159
+
```jsx
160
+
var hello;
161
+
hello = (
162
+
<div>
163
+
<p>Hello</p>
164
+
</div>
165
+
);
166
+
```
167
+
168
+
### `return`
169
+
170
+
The following patterns are considered warnings when configured `{return: "parens"}`.
84
171
85
172
```jsx
86
173
functionhello() {
@@ -90,7 +177,45 @@ function hello() {
90
177
}
91
178
```
92
179
93
-
The following patterns are not considered warnings when configured `{return: true}`.
180
+
The following patterns are not considered warnings when configured `{return: "parens"}`.
181
+
182
+
```jsx
183
+
functionhello() {
184
+
return (
185
+
<div>
186
+
<p>Hello</p>
187
+
</div>
188
+
);
189
+
}
190
+
```
191
+
192
+
```jsx
193
+
functionhello() {
194
+
return (<div>
195
+
<p>Hello</p>
196
+
</div>);
197
+
}
198
+
```
199
+
200
+
The following patterns are considered warnings when configured `{return: "parens-new-line"}`.
201
+
202
+
```jsx
203
+
functionhello() {
204
+
return<div>
205
+
<p>Hello</p>
206
+
</div>;
207
+
}
208
+
```
209
+
210
+
```jsx
211
+
functionhello() {
212
+
return (<div>
213
+
<p>Hello</p>
214
+
</div>);
215
+
}
216
+
```
217
+
218
+
The following patterns are not considered warnings when configured `{return: "parens-new-line"}`.
94
219
95
220
```jsx
96
221
functionhello() {
@@ -101,15 +226,48 @@ function hello() {
101
226
);
102
227
}
103
228
```
104
-
The following patterns are considered warnings when configured `{arrow: true}`.
229
+
230
+
### `arrow`
231
+
232
+
The following patterns are considered warnings when configured `{arrow: "parens"}`.
105
233
106
234
```jsx
107
235
varhello= () =><div>
108
236
<p>World</p>
109
237
</div>;
110
238
```
111
239
112
-
The following patterns are not considered warnings when configured `{arrow: true}`.
240
+
The following patterns are not considered warnings when configured `{arrow: "parens"}`.
241
+
242
+
```jsx
243
+
varhello= () => (
244
+
<div>
245
+
<p>World</p>
246
+
</div>
247
+
);
248
+
```
249
+
250
+
```jsx
251
+
varhello= () => (<div>
252
+
<p>World</p>
253
+
</div>);
254
+
```
255
+
256
+
The following patterns are considered warnings when configured `{arrow: "parens-new-line"}`.
257
+
258
+
```jsx
259
+
varhello= () =><div>
260
+
<p>World</p>
261
+
</div>;
262
+
```
263
+
264
+
```jsx
265
+
varhello= () => (<div>
266
+
<p>World</p>
267
+
</div>);
268
+
```
269
+
270
+
The following patterns are not considered warnings when configured `{arrow: "parens-new-line"}`.
0 commit comments