jsx-curly-spacing
Configuration
Enforce or disallow spaces inside of curly braces in JSX attributes and expressions.
Rule Details
This rule enforces a consistent style for the whitespace immediately inside JSX {...} braces — both when the braces wrap an attribute value and (optionally) when they wrap a child expression. It also handles the brace-spacing of JSXSpreadAttribute ({...obj}) the same way as a regular attribute brace.
By default the rule:
- Checks attribute braces (
attributesdefaults totrue). - Does not check child braces (
childrendefaults tofalse). - Disallows spaces inside the braces (
whendefaults to"never"). - Allows multi-line content inside the braces (
allowMultilinedefaults totrue).
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Rule Options
The rule accepts either a string shorthand ("never" / "always") or an options object. When using the shorthand, the options object may be supplied as the second argument:
The options object supports:
when:"never"(default) or"always"— whether spaces are required or disallowed inside braces.allowMultiline:true(default) orfalse— whether the contents may span multiple lines without a same-line space match.spacing: object with"objectLiterals": "never" | "always"— overrides the spacing rule when the contents are an immediate object literal ({{ ... }}).attributes:true(default) /false/{ when?, allowMultiline?, spacing? }— toggles or overrides the configuration for attribute braces.children:true/false(default) /{ when?, allowMultiline?, spacing? }— toggles or overrides the configuration for child braces.
Examples of incorrect code for this rule with "never":
Examples of correct code for this rule with "never":
Examples of incorrect code for this rule with "always":
Examples of correct code for this rule with "always":
Examples of incorrect code for this rule with { "allowMultiline": false }:
Examples of correct code for this rule with { "allowMultiline": false }:
Examples of incorrect code for this rule with { "spacing": { "objectLiterals": "always" } }:
Examples of correct code for this rule with { "spacing": { "objectLiterals": "always" } }:
Examples of incorrect code for this rule with { "children": true }:
Examples of correct code for this rule with { "children": true }: