Rule: object-literal-sort-keys

Checks ordering of keys in object literals.

When using the default alphabetical ordering, additional blank lines may be used to group object properties together while keeping the elements within each group in alphabetical order.

Rationale

Useful in preventing merge conflicts

Config

By default, this rule checks that keys are in alphabetical order. The following may optionally be passed:

  • “ignore-case” will compare keys in a case insensitive way.
  • “match-declaration-order” will prefer to use the key ordering of the contextual type of the object literal, as in:

    interface I { foo: number; bar: number; } const obj: I = { foo: 1, bar: 2 };

If a contextual type is not found, alphabetical ordering will be used instead.

  • “shorthand-first” will enforce shorthand properties to appear first, as in:

    const obj = { a, c, b: true };

Config examples
"object-literal-sort-keys": true
"object-literal-sort-keys": [true, "ignore-case", "match-declaration-order", "shorthand-first"]
Schema
{
  "type": "string",
  "enum": [
    "ignore-case",
    "match-declaration-order",
    "shorthand-first"
  ]
}