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. This rule preserves existing trailing commas; Prettier should be responsible for adding or removing them.
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.
Rule Details
// 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) {}
Options
This rule is not configurable.