Skip to content

complete/consistent-object-braces

💼 This rule is enabled in the ✅ recommended config.

📝 Requires object brace spacing to match the property count.

🔧 This rule is automatically fixable by the --fix CLI option.

Object literals with one property must be on one line unless that property value is another object literal. Object literals with two or more properties, object literals used as object property values, and object literals with object-valued properties must put each property on its own line. When automatically fixing an object literal to use multiple lines, the rule adds a trailing comma after every property.

This rule applies to object expressions, such as object literals assigned to variables, nested inside other objects, or passed as function arguments. It does not apply to object patterns, such as destructuring assignments or function parameters.

// Bad
const foo = {
bar,
};
// Good
const foo = { bar };
// Bad
const baz = { one, two };
// Good
const baz = {
one,
two,
};
// Bad
const qux = { nested: { value } };
// Good
const qux = {
nested: {
value,
},
};

This rule does not report destructuring patterns:

const { foo } = bar;
function foo({ bar }: Baz) {}

This rule is not configurable.