curly
JavaScript allows omitting braces around single-statement blocks. This rule enforces consistent brace usage.Rule Type: Suggestion
Fixable: Yes (automatically fixable)
Fixable: Yes (automatically fixable)
Why This Rule Exists
Omitting braces can lead to bugs when adding more statements:Rule Details
This rule enforces consistent brace usage forif, else, for, while, and do statements.
Options
This rule has several styles:"all" (default)
Always require braces around all control statements.
Incorrect:
"multi"
Require braces only when there are multiple statements.
Incorrect:
"multi-line"
Require braces when the statement spans multiple lines.
Incorrect:
"multi-or-nest"
Require braces when there are multiple statements OR nested statements.
Incorrect:
"consistent"
With multi options, enforce all branches of if-else-if chain to be consistent.
Incorrect:
Configuration Examples
Common Bug Patterns
The “goto fail” Bug
Adding Statements
Misleading Indentation
When to Use Each Style
”all” - Most Teams
- Prevents the “goto fail” class of bugs
- Makes code more maintainable
- Clear and consistent
”multi” or “multi-line” - Experienced Teams
Suitable if:- Team is very disciplined about code style
- You value conciseness
- You have good diff/review processes
”multi-or-nest” - Balanced Approach
Good middle ground:- Allows simple single-line statements
- Requires braces for complex cases
- Prevents most common bugs
When Not to Use It
Disable this rule if:- You don’t want to enforce a particular brace style
- You use a formatter like Prettier (which handles braces)
- Your team hasn’t agreed on a brace style
Auto-fixing
This rule is auto-fixable:Related Rules
- brace-style - Brace placement style
- nonblock-statement-body-position - Position of single-line bodies
- arrow-body-style - Arrow function body style