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
Copy file name to clipboardExpand all lines: docs/rules/jsx-tag-spacing.md
+46-3Lines changed: 46 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,23 @@
1
1
# Validate whitespace in and around the JSX opening and closing brackets (react/jsx-tag-spacing)
2
2
3
-
Enforce or forbid spaces after the opening bracket, before the closing bracket of self-closing elements, and between the angle bracket and slash of JSX closing or self-closing elements.
3
+
Enforce or forbid spaces after the opening bracket, before the closing bracket, before the closing bracket of self-closing elements, and between the angle bracket and slash of JSX closing or self-closing elements.
4
4
5
5
**Fixable:** This rule is automatically fixable using the `--fix` flag on the command line.
6
6
7
7
## Rule Details
8
8
9
9
This rule checks the whitespace inside and surrounding the JSX syntactic elements.
10
10
11
-
This rule takes one argument, an object with 3 possible keys: `closingSlash`, `beforeSelfClosing`and `afterOpening`. Each key can receive the value `"allow"` to disable that specific check.
11
+
This rule takes one argument, an object with 4 possible keys: `closingSlash`, `beforeSelfClosing`, `afterOpening`, and `beforeClosing`. Each key can receive the value `"allow"` to disable that specific check.
12
12
13
13
The default values are:
14
14
15
15
```json
16
16
{
17
17
"closingSlash": "never",
18
18
"beforeSelfClosing": "always",
19
-
"afterOpening": "never"
19
+
"afterOpening": "never",
20
+
"beforeClosing": "never"
20
21
}
21
22
```
22
23
@@ -176,6 +177,48 @@ The following patterns are **not** considered warnings when configured `"allow-m
176
177
/>
177
178
```
178
179
180
+
### `beforeClosing`
181
+
182
+
This check can be set to `"always"`, `"never"`, or `"allow"` (to disable it).
183
+
184
+
If it is `"always"` the check warns whenever whitespace is missing before the closing bracket of a JSX opening element or whenever a space is missing before the closing bracket closing element. If `"never"`, them it warns if a space is present before the closing bracket of either a JSX opening element or closing element. This rule will never warn for self closing JSX elements. The default value of this check is `"never"`.
185
+
186
+
The following patterns are considered warnings when configured `"always"`:
187
+
188
+
```jsx
189
+
<Hello></Hello>
190
+
<Hello></Hello >
191
+
<Hello ></Hello>
192
+
```
193
+
194
+
The following patterns are **not** considered warnings when configured `"always"`:
195
+
196
+
```jsx
197
+
<Hello ></Hello >
198
+
<Hello
199
+
firstName="John"
200
+
>
201
+
</Hello >
202
+
```
203
+
204
+
The following patterns are considered warnings when configured `"never"`:
205
+
206
+
```jsx
207
+
<Hello ></Hello>
208
+
<Hello></Hello >
209
+
<Hello ></Hello >
210
+
```
211
+
212
+
The following patterns are **not** considered warnings when configured `"never"`:
213
+
214
+
```jsx
215
+
<Hello></Hello>
216
+
<Hello
217
+
firstName="John"
218
+
>
219
+
</Hello>
220
+
```
221
+
179
222
## When Not To Use It
180
223
181
224
You can turn this rule off if you are not concerned with the consistency of spacing in or around JSX brackets.
0 commit comments