jsonc/sort-array-values
require array values to be sorted
- 🔧 The
--fix
option on the command line can automatically fix some of the problems reported by this rule.
📖 Rule Details
This rule checks values of array and verifies that values are sorted alphabetically or specified order.
🔧 Options
json5
{
"jsonc/sort-array-values": ["error",
{
"pathPattern": "^files$", // Hits the files property
"order": { "type": "asc" }
},
{
"pathPattern": "^keywords$", // Hits the keywords property
"order": [
"eslint",
"eslintplugin",
"eslint-plugin",
{
// Fallback order
"order": { "type": "asc" }
}
]
}
]
}
The option receives multiple objects with the following properties:
pathPattern
(Required) ... Defines the regular expression pattern of paths to which you want to enforce the order. If you want to apply to the top level, define"^$"
.order
(Required) ... Defines how to enforce the order. You can use an object or an array.- Array ... Defines an array of values to enforce the order.
- String ... Defines the value.
- Object ... The object has the following properties:
valuePattern
... Defines a pattern to match the value. Default is to match all.order
... The object has the following properties:type
:"asc"
... Enforce values to be in ascending order. This is default."desc"
... Enforce values to be in descending order.
caseSensitive
... Iftrue
, enforce values to be in case-sensitive order. Default istrue
.natural
... Iftrue
, enforce values to be in natural order. Default isfalse
.
- Object ... The object has the following properties:
type
:"asc"
... Enforce values to be in ascending order. This is default."desc"
... Enforce values to be in descending order.
caseSensitive
... Iftrue
, enforce values to be in case-sensitive order. Default istrue
.natural
... Iftrue
, enforce values to be in natural order. Default isfalse
.
- Array ... Defines an array of values to enforce the order.
minValues
... Specifies the minimum number of values that an array should have in order for the array's unsorted values to produce an error. Default is2
, which means by default all arrays with unsorted values will result in lint errors.
👫 Related rules
🚀 Version
This rule was introduced in eslint-plugin-jsonc v2.2.0