Skip to main content

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.