object-format
Enforce object literal line format based on property count.
Targeted pattern scope
This rule checks ObjectExpression nodes with more than one property and
enforces single-line or multi-line formatting based on property count.
What this rule reports
For each object literal with at least two properties:
- if property count is less than or equal to
maxProperties, the object must be on a single line; - otherwise, the object must span multiple lines.
Why this rule exists
Object literals with inconsistent line formatting are harder to scan. A threshold-based policy keeps short objects compact while forcing larger objects to be readable.
❌ Incorrect
// default maxProperties: 1
const point = { x: 1, y: 2 };
✅ Correct
// default maxProperties: 1
const point = {
x: 1,
y: 2,
};
// with { maxProperties: 2 }
const point = { x: 1, y: 2 };
Behavior and migration notes
This rule currently reports only and does not provide an autofix.
Adopt in warning mode first, then align formatting manually (or with codemods)
before enforcing as error.
Options
type Options = [
{
maxProperties?: number; // default: 1
},
];
maxProperties: maximum number of properties allowed on one line.
Default configuration
[{ maxProperties: 1 }];
Additional examples
const pair = { left: 1, right: 2 };
// ✅ valid when configured with { maxProperties: 2 }
const tupleLike = {
first: 1,
second: 2,
third: 3,
};
// ✅ required when maxProperties is 2
ESLint flat config example
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/object-format": "error",
},
},
];
When not to use it
Disable this rule if Prettier (or another formatter) already defines the object wrapping strategy you want and this threshold approach conflicts with it.
Package documentation
Rule catalog ID: R053
Further reading
Adoption resources
- Start at warning level in CI, then move to error after cleanup.
- Use focused codemods/autofix batches per package or directory.