Skip to content

order-properties

💼 This rule is enabled in the 🎨 stylistic config.

🔧 This rule is automatically fixable by the --fix CLI option.

A conventional order exists for package.json top-level properties. npm does not enforce this order, but for consistency and readability, this rule can enforce it. We use the order specified in sort-package-json as the default sort order. Any properties not defined by this ordering are placed after the standard fields and sorted lexicographically.

{
"version": "1.0.0",
"name": "my-package"
}
Name Description Default
order Specifies the sorting order of top-level properties. sort-package-json

The order property specifies the sorting order of package properties. Pass in:

  • "sort-package-json" - to order properties by the default order specified in sort-package-json.
  • string[] - to specify an array of top-level package properties to lint sorting on only those properties. All properties not in this collection will be sorted by “sort-package-json” specifications.
  • "legacy" (deprecated) - to order properties specified by npm documentation.
{
"package-json/order-properties": [
"error",
{
"order": "sort-package-json"
}
]
}
  • sort-collections - Enforces that collection fields (e.g. dependencies, files) are sorted.