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: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -123,7 +123,7 @@ Finally, enable all of the rules that you would like to use. Use [our preset](#
123
123
*[react/jsx-boolean-value](docs/rules/jsx-boolean-value.md): Enforce boolean attributes notation in JSX (fixable)
124
124
*[react/jsx-closing-bracket-location](docs/rules/jsx-closing-bracket-location.md): Validate closing bracket location in JSX (fixable)
125
125
*[react/jsx-closing-tag-location](docs/rules/jsx-closing-tag-location.md): Validate closing tag location in JSX (fixable)
126
-
*[react/jsx-curly-spacing](docs/rules/jsx-curly-spacing.md): Enforce or disallow spaces inside of curly braces in JSX attributes (fixable)
126
+
*[react/jsx-curly-spacing](docs/rules/jsx-curly-spacing.md): Enforce or disallow spaces inside of curly braces in JSX attributes and expressions (fixable)
127
127
*[react/jsx-equals-spacing](docs/rules/jsx-equals-spacing.md): Enforce or disallow spaces around equal signs in JSX attributes (fixable)
128
128
*[react/jsx-filename-extension](docs/rules/jsx-filename-extension.md): Restrict file extensions that may contain JSX
129
129
*[react/jsx-first-prop-new-line](docs/rules/jsx-first-prop-new-line.md): Enforce position of the first prop in JSX (fixable)
# Enforce or disallow spaces inside of curly braces in JSX attributes. (react/jsx-curly-spacing)
1
+
# Enforce or disallow spaces inside of curly braces in JSX attributes and expressions. (react/jsx-curly-spacing)
2
2
3
3
While formatting preferences are very personal, a number of style guides require or disallow spaces between curly braces.
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
-
This rule aims to maintain consistency around the spacing inside of JSX attributes.
9
+
This rule aims to maintain consistency around the spacing inside of JSX attributes and expressions inside element children.
10
10
11
11
It either requires or disallows spaces between those braces and the values inside of them.
12
12
13
-
###Options
13
+
##Rule Options
14
14
15
15
There are two main options for the rule:
16
16
17
-
*`"always"` enforces a space inside of curly braces
18
-
*`"never"` disallows spaces inside of curly braces (default)
17
+
*`{"when": "always"}` enforces a space inside of curly braces
18
+
*`{"when": "never"}` disallows spaces inside of curly braces (default)
19
19
20
-
Depending on your coding conventions, you can choose either option by specifying it in your configuration:
20
+
There are also two properties that allow specifying how the rule should work with the attributes (`attributes`) and the expressions (`children`). The possible values are:
21
21
22
-
```json
23
-
"react/jsx-curly-spacing": [2, "always"]
22
+
*`true` enables checking for the spacing using the options (default for `attributes`), e.g. `{"attributes": false}` disables checking the attributes
23
+
*`false` disables checking for the spacing (default for `children`, for backward compatibility), e.g. `{"children": true}` enables checking the expressions
24
+
* an object containing options that override the global options, e.g. `{"when": "always", "children": {"when": "never"}}` enforces a space inside attributes, but disallows spaces inside expressions
25
+
26
+
### never
27
+
28
+
When `{"when": "never"}` is set, the following patterns are considered warnings:
By default, braces spanning multiple lines are allowed with either setting. If you want to disallow them you can specify an additional `allowMultiline` property with the value `false`:
@@ -135,6 +221,41 @@ When `"never"` is used and `objectLiterals` is `"always"`, the following pattern
135
221
136
222
Please note that spacing of the object literal curly braces themselves is controlled by the built-in [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing) rule.
137
223
224
+
### Shorthand options
225
+
226
+
To preserve backward compatibility, two additional options are supported:
0 commit comments