Skip to content

🚀 Feature: sort-collections also sorts the object properties within arrays #1967

Description

@ShayanTheNerd

Feature Request Checklist

Overview

The current implementation could be extended to support sorting the objects within an array with wildcard patterns (e.g., <array-key>.*). For example, it could then sort the properties of each object in the contributors array. Using a pattern similar to the current key/order pattern to express this:

'package-json/sort-collections': ['warn', [
  {
    key: 'contributors.*',
    order: ['name', 'email', 'url'],
  },
]],

Input:

{
  "contributors": [
    {
      "url": "https://example.com/bob",
      "name": "Bob",
      "email": "bob@example.com"
    },
    {
      "email": "alice@example.com",
      "name": "Alice"
    }
  ]
}

Output:

{
  "contributors": [
    {
      "name": "Bob",
      "email": "bob@example.com",
      "url": "https://example.com/bob"
    },
    {
      "name": "Alice",
      "email": "alice@example.com"
    }
  ]
}

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: accepting prsPlease, send a pull request to resolve this! 🙏type: featureNew enhancement or request 🚀

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions