Skip to main content

curly

JavaScript allows omitting braces around single-statement blocks. This rule enforces consistent brace usage.
Rule Type: Suggestion
Fixable: Yes (automatically fixable)

Why This Rule Exists

Omitting braces can lead to bugs when adding more statements:
Many style guides recommend always using braces for clarity and bug prevention.

Rule Details

This rule enforces consistent brace usage for if, else, for, while, and do statements.

Options

This rule has several styles:

"all" (default)

Always require braces around all control statements. Incorrect:
Correct:

"multi"

Require braces only when there are multiple statements. Incorrect:
Correct:

"multi-line"

Require braces when the statement spans multiple lines. Incorrect:
Correct:

"multi-or-nest"

Require braces when there are multiple statements OR nested statements. Incorrect:
Correct:

"consistent"

With multi options, enforce all branches of if-else-if chain to be consistent. Incorrect:
Correct:

Configuration Examples

Common Bug Patterns

The “goto fail” Bug

This famous Apple SSL bug could have been prevented by always using braces.

Adding Statements

Misleading Indentation

When to Use Each Style

”all” - Most Teams

Best for teams that want maximum safety and clarity. Recommended for most projects.
  • 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:
  1. You don’t want to enforce a particular brace style
  2. You use a formatter like Prettier (which handles braces)
  3. Your team hasn’t agreed on a brace style

Auto-fixing

This rule is auto-fixable: