Skip to content

Latest commit

 

History

History
77 lines (54 loc) · 2.09 KB

order-properties.md

File metadata and controls

77 lines (54 loc) · 2.09 KB

order-properties

💼 This rule is enabled in the ✅ recommended 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.

💡 This rule is especially useful in monorepos with many package.json files that would ideally be consistently ordered.

Rule Details

This rule detects when properties in package.json are out of order.

Examples of incorrect code for this rule:

{
	"version": "1.0.0",
	"name": "my-package"
}

This is an error because "version" should come after "name".

Examples of correct code for this rule:

{
	"name": "my-package",
	"version": "1.0.0"
}

Options

{
	"package-json/order-properties": [
		"error",
		{
			"order": "sort-package-json"
		}
	]
}

Order

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

  • "legacy" - to order properties specified by npm documentation.
  • "sort-package-json" - to order properties by the default order specified in sort-package-json.
  • Array<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.
interface {
	order?: "legacy" | "sort-package-json" | Array<string>
}

Default: "sort-package-json"

⚠️ The default value for order changed from "legacy" to "sort-package-json" in v0.6.0.

This rule is autofixable; run eslint with the --fix option to sort top-level properties in place. Any properties not present in the array of ordered properties will be left in their original positions.